0

我设法将值插入范围向量,但在范围向量中我有数据 RangeA、RangeB、RangeC..

使用这些数据,我想在块向量下为这个范围创建一个向量,我应该怎么做?

vector <string> range;
for(int i=0;i<range.size();i++)
{
    cout<<"range: "<<range[i]<<endl;
    vector <string> block[i];                  <<<<<<<
}

输出:

范围:范围A

范围:范围B

范围:范围C

提前致谢!

4

2 回答 2

0
vector<string> range;
//Create block vector with size
//same as range vector
vector <string> block(range.size());
//Now you can iterate range vector 
//and initialize the block vector with value 
for (int i = 0 ; i < range.size(); i++)
{
    block[i]=string(range[i]);
}
for (int i = 0 ; i < block.size(); i++)
{
    cout<<block[i];
}
于 2013-08-12T06:15:41.660 回答
0
vector <string> range;
for(int i=0;i<range.size();i++)
{
    cout<<"range: "<<range[i]<<endl;

    // create a vector of size i
    // with each element of default 
    // value "default"
    vector <string> block(i,string("default")); 
}
于 2013-08-10T17:42:50.793 回答