developer tip

Qt C ++ 집계 'std :: stringstream ss'에 불완전한 유형이 있으며 정의 할 수 없습니다.

copycodes 2020. 9. 14. 21:20
반응형

Qt C ++ 집계 'std :: stringstream ss'에 불완전한 유형이 있으며 정의 할 수 없습니다.


정수를 문자열로 변환하는 프로그램에이 함수가 있습니다.

    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();
}

또한 변환하는 다른 방법을 사용할 수 있습니다 intstring같은,

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

이것을 확인 하십시오!

참고 URL : https://stackoverflow.com/questions/11751486/qt-c-aggregate-stdstringstream-ss-has-incomplete-type-and-cannot-be-define

반응형