<分区>
所以基本上我想找出的是这种情况:
std::string input;
Ask user for a string?: Apples
cin >> input;
std::string Apples = "input";
基本上,我向用户询问一个字符串,然后创建一个具有该字符串名称的变量。这可能吗?
标签 c++
<分区>
所以基本上我想找出的是这种情况:
std::string input;
Ask user for a string?: Apples
cin >> input;
std::string Apples = "input";
基本上,我向用户询问一个字符串,然后创建一个具有该字符串名称的变量。这可能吗?
最佳答案
不,你不能那样做。
最接近的功能是使用 map 。
std::map<std::string, int> aMap;
关于c++ - 是否可以将变量声明为字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30696345/