我设法将值插入范围向量,但在范围向量中我有数据RangeA,RangeB,RangeC ..
使用这些数据,我想在块矢量下为这个范围创建一个矢量,我该怎么做呢?
vector <string> range;
for(int i=0;i<range.size();i++)
{
cout<<"range: "<<range[i]<<endl;
vector <string> block[i]; <<<<<<<
}
输出:
范围:RangeA
范围:RangeB
范围:RangeC
提前致谢!
答案 0 :(得分: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"));
}
答案 1 :(得分: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];
}