我的程序中有这个函数可以将整数转换为字符串:
QString Stats_Manager::convertInt(int num)
{
stringstream ss;
ss << num;
return ss.str();
}
但是当我运行这个时,我得到了错误:
aggregate 'std::stringstream ss' has incomplete type and cannot be defined
我不太确定那是什么意思。但是,如果您知道如何修复它或需要更多代码,请发表评论。谢谢。
#include <sstream>
你可能有一个类的前向声明,但没有包含标题:
#include <sstream>
//...
QString Stats_Manager::convertInt(int num)
{
std::stringstream ss; // <-- also note namespace qualification
ss << num;
return ss.str();
}
就像上面写的一样,您忘记输入 #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!
不定期副业成功案例分享