我试图使用<<
作为将整数移动到字符串流中的方法。我必须有一些基本和基本的东西。最简单的代码甚至无法编译:
std::stringstream ss;
ss << "simple test ";
产生此错误:
错误C2297:&#39;&lt;&lt;&#39; :非法,右操作数有类型&#39; const char [13]&#39;
答案 0 :(得分:3)
这不是一个有效的C ++程序。
首先,您需要加入sstream
。然后,您需要将带有<<
的表达式放入函数。
像这样:
#include <sstream>
int main()
{
std::stringstream ss;
ss << "simple test ";
}
答案 1 :(得分:0)
这有效:
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main()
{
stringstream ss;
string s;
ss << "simple test ";
s = ss.str();
cout << s;
return 0;
}