PDA

View Full Version : Compile error from newbie to g++ and Qt



vieraci
4th May 2007, 15:00
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::ostringstream strbuf’ has incomplete type and cannot be defined

This is the program:


#include <iostream>
int main()
{
using namespace std;
ostringstream strbuf;
int lucky=7;
float pi=3.14;
double e=2.71;
strbuf << "lucky number " << lucky << endl
<< "pi " << pi << endl
<< "e " << e << endl;
string strval=strbuf.str();
cout << strval;
ofstream outf;
outf.open("mydata");
outf << strval;
outf.close();
return 0;
}

wysota
4th May 2007, 15:07
You need to include <sstream> as well.

vieraci
4th May 2007, 23:27
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 ? :confused:

jpn
5th May 2007, 06:09
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>.


are the headers documented somewhere ? :confused:
http://www.cplusplus.com/reference/

wysota
5th May 2007, 08:23
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.