如何在C ++中使用字符串作为变量名? [英] How to use a string as a variable name in C++?

查看:2193
本文介绍了如何在C ++中使用字符串作为变量名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

将字符串转换为变量名称或变量类型

如何在c ++中使用字符串值作为变量名

How to use the string value as a variable name in c++

string listName = "hari";
string vectorName = "BF_vector_"+listName;
vector<string> vectorName;

vectorName.push_back("Some Value");

如何使用vectorName的字符串值(BF_vector_hari)作为向量的变量名。
提前感谢。

How to use the string value("BF_vector_hari") of vectorName as a variable name of vector.? Thanks in advance.

推荐答案

不能在C ++中。

你可以做的是使用 std :: map< std :: string,std :: vector> 的形式存储名称到向量图。

One thing you can do is use a form of std::map<std::string, std::vector> to store name to vector map.

这篇关于如何在C ++中使用字符串作为变量名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆