【问题标题】:Qt c++ aggregate 'std::stringstream ss' has incomplete type and cannot be definedQt c++聚合'std :: stringstream ss'类型不完整,无法定义
【发布时间】:2012-07-29 21:23:06
【问题描述】:
我的程序中有这个函数可以将整数转换为字符串:
QString Stats_Manager::convertInt(int num)
{
stringstream ss;
ss << num;
return ss.str();
}
但是当我运行它时,我得到了错误:
aggregate 'std::stringstream ss' has incomplete type and cannot be defined
我不太确定这意味着什么。但是,如果您知道如何修复它或需要更多代码,请发表评论。谢谢。
【问题讨论】:
标签:
c++
string
qt
stringstream
【解决方案1】:
你可能有一个类的前向声明,但没有包含标题:
#include <sstream>
//...
QString Stats_Manager::convertInt(int num)
{
std::stringstream ss; // <-- also note namespace qualification
ss << num;
return ss.str();
}
【解决方案2】:
就像上面写的一样,你忘记输入#include <sstream>
#include <sstream>
using namespace std;
QString Stats_Manager::convertInt(int num)
{
stringstream ss;
ss << num;
return ss.str();
}
你也可以使用一些其他的方式将int转换成string,比如
char numstr[21]; // enough to hold all numbers up to 64-bits
sprintf(numstr, "%d", age);
result = name + numstr;
查看this!