0

I am up to upgrade a program to make it dynamically configurable from files. What i need is a number of vector viables, and that number being dependant of int variable.

int k=4 //loaded from file, i handled it

vector<string> NAME(k)

Moreover, names of those variables need to be rising numbers (first object: NAME1, second NAME2 etc.).

This is my first ever post there, so sorry for all the mistakes or lack of information :)

4

2 回答 2

2

您不能动态命名变量,但可以将它们存储在地图中。

std::map<std::string, std::vector<std::string> > myVectors;

for (int i = 0; i < k; ++i)
{
  std::ostringstream name;
  name << "NAME" << i;

  myVectors.insert(std::make_pair(name.str(), std::vector<std::string>()));
}
于 2013-08-08T11:42:09.513 回答
0

利用

vector<vector<string> > name(k);

你从哪里得到名字?我从文件中取而代之。再次阅读时可能是的,对不起。没有解决部分以上的问题。

于 2013-08-08T11:41:55.920 回答