在C ++中声明具有可变维数的多维向量

时间:2017-08-30 17:58:45

标签: c++ multidimensional-array vector

我正在尝试声明具有可变维数(用户输入)的多维向量。

这就是我所拥有的:

CREATE OR REPLACE PROCEDURE STS_OWNER.PRC_CAMBIO_LDC1 IS 
     CURSOR LDC1 IS 
          select CASE_NO 
          from ldc_cases 
          where case_no in (select barcode 
                            from sts_tracking 
                            where ldc='0' 
                            and duplicated='0'); 
          FOR UPDATE BARCODE; 
     BARCODE VARCHAR2(50); 
BEGIN 
    OPEN LDC1;
    FETCH LDC1 INTO BARCODE; 
    WHILE LDC1%FOUND LOOP 
         update sts_tracking 
         set ldc= 1 
         WHERE CURRENT LDC1; 
         FETCH LDC1 INTO BARCODE; 
     END LOOP;
     CLOSE LDC1; 
     COMMIT; 
END;

另一个解决方案是在开头使用if语句,但我想知道是否存在其他解决方案?

#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

vector< double > data;

int main() {
    int numberDimensions = 4;
    for (int it = 0; it < numberDimensions; it++){
      // Nor sure what to put here
    }
    return 0;
}

感谢您的任何建议,

1 个答案:

答案 0 :(得分:0)

正如评论中所建议的那样是我遵循的解决方案:

#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

vector< double > data;

int main() {

    std::vector<int> parameter1 {34,23,58};
    std::vector<int> parameter2 {1,2,3};

    data = vector< double > (parameter1.size()*parameter2.size());
    calculateResult(data);

   // If I want to access the result for Parameter1 = 58 and Parameter = 2 I do:
    int index1 = 2
    int index2 = 1
    double selectedResult = data[index1*parameter1.size()+index2];

    return 0;
}