Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 696
tyty5949 Avatar asked Aug 01 '12 01:08

tyty5949


People also ask

What is std :: StringStream?

Stream class to operate on strings. Objects of this class use a string buffer that contains a sequence of characters. This sequence of characters can be accessed directly as a string object, using member str .

How do you clear a string stream?

How to Clear StringStream in C++ You can easily clear the content of a StringStream object by using the predefined ss. clear() function. The function will erase the data in the buffer and make the object empty.


2 Answers

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(); } 
like image 198
Luchian Grigore Avatar answered Sep 16 '22 19:09

Luchian Grigore


Like it's written up there, you forget to type #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 int to string, like

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

check this!

like image 33
booiljoung Avatar answered Sep 20 '22 19:09

booiljoung