繁体   English   中英

Qt c ++聚合'std :: stringstream ss'类型不完整,无法定义

[英]Qt c++ aggregate 'std::stringstream ss' has incomplete type and cannot be defined

我在我的程序中有这个函数将整数转换为字符串:

    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>

//...
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;

检查一下!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM