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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11751486/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 15:30:05  来源:igfitidea点击:

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

c++stringqtstringstream

提问by tyty5949

I have this function in my program that converts integers to strings:

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

    QString Stats_Manager::convertInt(int num)
    {
        stringstream ss;
        ss << num;
        return ss.str();
    }

But when ever i run this i get the error:

但是当我运行这个时,我收到错误:

aggregate 'std::stringstream ss' has incomplete type and cannot be defined

Im not really sure what that means. But if you know how to fix it or need any more code please just comment. Thanks.

我不太确定这意味着什么。但是,如果您知道如何修复它或需要更多代码,请发表评论。谢谢。

回答by Luchian Grigore

You probably have a forward declaration of the class, but haven't included the header:

你可能有一个类的前向声明,但没有包含标题:

#include <sstream>

//...
QString Stats_Manager::convertInt(int num)
{
    std::stringstream ss;   // <-- also note namespace qualification
    ss << num;
    return ss.str();
}

回答by booiljoung

Like it's written up there, you forget to type #include <sstream>

就像写在那里一样,你忘记打字了 #include <sstream>

#include <sstream>
using namespace std;

QString Stats_Manager::convertInt(int num)
{
   stringstream ss;
   ss << num;
   return ss.str();
}

You can also use some other ways to convert intto string, like

您还可以使用其他一些方式转换intstring,例如

char numstr[21]; // enough to hold all numbers up to 64-bits
sprintf(numstr, "%d", age);
result = name + numstr;

check this!

检查这个!