2012-08-01 5 views
67

mam tej funkcji w moim programie, który konwertuje liczby całkowite do strun:Qt C++ agregat „std :: stringstream ss” ma niekompletną typu i nie mogą być definiowane

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

Ale gdy kiedykolwiek uruchomić to pojawia się błąd :

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

Nie jestem naprawdę pewien, co to oznacza. Ale jeśli teraz, jak to naprawić lub potrzebujesz więcej kodu, po prostu skomentuj. Dzięki.

+37

'' #include Managu

+1

Tak na marginesie, QString ma statyczną funkcję konstruowania ciąg od liczby. Jest to [QString :: number] (http://doc.qt.nokia.com/4.8-snapshot/qstring.html#number). – cgmb

Odpowiedz

106

Prawdopodobnie masz do przodu deklarację klasy, ale nie zawiera nagłówek:

#include <sstream> 

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

jak jest napisane tam, zapomni wpisać #include <sstream>

#include <sstream> 
using namespace std; 

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

można również użyj innych sposobów konwersji int na string, takich jak

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

check this!

+3

'using std;' jest nieprawidłowe. Czy próbowałeś kompilować? –