将变量值保存为字符串

将变量值保存为字符串

问题描述:

我正在努力做一件看似简单的事情,我无法做到。我想知道是否有人可以提供帮助。 :(



我想将变量的值传递给字符串。变量可以是任何类型,int,string等。



理想情况下,我需要类似的东西,



cout<< var1;



但是我希望将var1的值复制到std :: string变量中。我该怎么办?:(

I am struggling a seemingly easy thing am trying to do, and I am unable to do it. I was wondering if someone can help. :(

I want to pass in the value of a variable into a string. The variable can be of any type, int, string, etc.

Ideally I want something like,

cout<<var1;

but I want the value of var1 copied into a std::string variable. how can I do this? :(

你需要一个字符串流类型 [ ^ ]。