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:
#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;
}
#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;
}
To copy to clipboard, switch view to plain text mode
Bookmarks