Results 1 to 5 of 5

Thread: Compile error from newbie to g++ and Qt

  1. #1
    Join Date
    Apr 2007
    Location
    Sunny Darwin, NT Australia
    Posts
    186
    Thanks
    29
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Compile error from newbie to g++ and Qt

    Trying to compile a simple example from a book, I get an error that I don't know what it means. Can anyone give any clues please ?

    This is the command line and error message:

    g++ -ansi -pedantic -Wall -o test test.cpp
    test.cpp: In function ‘int main()’:
    test.cpp:7: error: aggregate ‘std:stringstream strbuf’ has incomplete type and cannot be defined

    This is the program:

    Qt Code:
    1. #include <iostream>
    2. int main()
    3. {
    4. using namespace std;
    5. ostringstream strbuf;
    6. int lucky=7;
    7. float pi=3.14;
    8. double e=2.71;
    9. strbuf << "lucky number " << lucky << endl
    10. << "pi " << pi << endl
    11. << "e " << e << endl;
    12. string strval=strbuf.str();
    13. cout << strval;
    14. ofstream outf;
    15. outf.open("mydata");
    16. outf << strval;
    17. outf.close();
    18. return 0;
    19. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 4th May 2007 at 15:07.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Compile error from newbie to g++ and Qt

    You need to include <sstream> as well.

  3. #3
    Join Date
    Apr 2007
    Location
    Sunny Darwin, NT Australia
    Posts
    186
    Thanks
    29
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Compile error from newbie to g++ and Qt

    Thank you.
    So I assume "incomplete type and cannot be defined" means "cannot resolve dependencies"
    Original error went away, now ofstream has has same problem.
    Including <ofstream> said "file not found" and <ostream> made no difference. I thought it would have been standard c/c++ headers ? are the headers documented somewhere ?

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Compile error from newbie to g++ and Qt

    Quote Originally Posted by vieraci View Post
    Original error went away, now ofstream has has same problem.
    Including <ofstream> said "file not found" and <ostream> made no difference. I thought it would have been standard c/c++ headers ?
    Include <fstream>.

    Quote Originally Posted by vieraci View Post
    are the headers documented somewhere ?
    http://www.cplusplus.com/reference/
    J-P Nurmi

  5. The following user says thank you to jpn for this useful post:

    vieraci (8th May 2007)

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Compile error from newbie to g++ and Qt

    Quote Originally Posted by vieraci View Post
    So I assume "incomplete type and cannot be defined" means "cannot resolve dependencies"
    It means you're referrencing some identifier as a class which hasn't been defined.

Similar Threads

  1. Compile Errors
    By luffy27 in forum Qt Programming
    Replies: 3
    Last Post: 4th November 2006, 05:26
  2. how to correctly compile threads support?
    By srhlefty in forum Installation and Deployment
    Replies: 9
    Last Post: 25th June 2006, 19:15
  3. QT/Win 4.1.1 with VisualStudio2005 Newbie
    By skaiser in forum Installation and Deployment
    Replies: 9
    Last Post: 24th March 2006, 02:26
  4. TIP: If Qt4.1 debug compile doesn't work...
    By pthomas in forum Newbie
    Replies: 3
    Last Post: 13th January 2006, 14:36

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.