【发布时间】:2018-06-13 20:00:02
【问题描述】:
string toString() {
std::stringstream punkte;
std::stringstream name;
std::cout << name << "hat" << punkte << "Punkte" << '\n'
return 0;
}
在这行代码。我收到错误 C++
std::cout << name << "hat" << punkte << "Punkte" << '\n';
我也在我的代码中包含了这个:
#include <string> // std::string
#include <iostream> // std::cout
#include <sstream> // std::stringstream, std::stringbuf
#include <fstream>
【问题讨论】:
-
我想你的意思是:
std::cout << name.str() << "hat" << punkte.str() << "Punkte" << '\n'; -
你能添加你的错误信息吗?
-
还有
return 0;- 零不是字符串。您正在尝试从空指针创建字符串。 -
@DimChtz 不,name 和 punkte 是属性。我已经初始化了。
-
它们不是属性,它们是局部变量。这段代码毫无意义。
标签: c++ string visual-studio operator-keyword stringstream