Gcc 4.x

I have a great many program sources that compiled excellent with gcc 3.5.x

Then gcc 4. was released. Input and output had marvelous colours. The
only problem was that it could not compile my older programs and exited
with unexplained questionmarks in error messages like those below.

I decided to wait for a better release of gcc. That was over a year ago,
and I cannot wait endlessly.

This simple program after www.cplusplus.com/doc/tutorial/files::Input\
Output with files :

using namespace std;

#include <iostream>
#include <ostream>

int main ( ) {
ofstream Myfile;
Myfile.open ("example.txt");
Myfile << "Piet is gek\n";
Myfile.close ();
return 1;
}


gives me this unexplained error message:

GccWritetest.cc: In function ‘int main()’:
GccWritetest.cc:7: error: aggregate ‘std::ofstream Myfile’ has incomplete type
and cannot be defined

****** is there anubody that can tell me how to solve this? ****

For info: `g++ -v` gives:

Using built-in specs.
Target: x86_64-suse-linux
Configured with: ../configure --prefix=/usr --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64 --enable-languages=c,c++,objc,fortran,obj-c++,java,ada --enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.4 --enable-ssp --disable-libssp --with-bugurl=http://bugs.opensuse.org/ --with-pkgversion='SUSE Linux' --disable-libgcj --disable-libmudflap --with-slibdir=/lib64 --with-system-zlib --enable-__cxa_atexit --enable-libstdcxx-allocator=new --disable-libstdcxx-pch --enable-version-specific-runtime-libs --program-suffix=-4.4 --enable-linux-futex --without-system-libunwind --with-arch-32=i586 --with-tune=generic --build=x86_64-suse-linux
Thread model: posix
gcc version 4.4.1 [gcc-4_4-branch revision 150839] (SUSE Linux)


0000000 G c c W r i t e t e s t . c c :
0000020 sp I n sp f u n c t i o n sp b nul can
0000040 i n t sp m a i n ( ) b nul em : nl G
0000060 c c W r i t e t e s t . c c : 7
0000100 : sp e r r o r : sp a g g r e g a
0000120 t e sp b nul can s t d : : o f s t r
0000140 e a m sp M y f i l e b nul em sp h a
0000160 s sp i n c o m p l e t e sp t y p
0000200 e sp a n d sp c a n n o t sp b e sp
0000220 d e f i n e d nl
0000230


0000000 107 143 143 127 162 151 164 145 164 145 163 164 056 143 143 072
0000020 040 111 156 040 146 165 156 143 164 151 157 156 040 342 200 230
0000040 151 156 164 040 155 141 151 156 050 051 342 200 231 072 012 107
0000060 143 143 127 162 151 164 145 164 145 163 164 056 143 143 072 067
0000100 072 040 145 162 162 157 162 072 040 141 147 147 162 145 147 141
0000120 164 145 040 342 200 230 163 164 144 072 072 157 146 163 164 162
0000140 145 141 155 040 115 171 146 151 154 145 342 200 231 040 150 141
0000160 163 040 151 156 143 157 155 160 154 145 164 145 040 164 171 160
0000200 145 040 141 156 144 040 143 141 156 156 157 164 040 142 145 040
0000220 144 145 146 151 156 145 144 012
0000230

It looks to me that bytes \200 \230 and \200 \231 lead to the disturbing
question marks. I wonder what use they have.

And it looks to me that the error message "... Myfile’ has incomplete type ..."
refers to the c++ files and not to mine.
-----

fstream, not ostream.
using namespace std; is missing and you're returning 1 from main (should only be done if the program was unsuccessful).
1
2
3
4
5
6
7
8
9
10
11
12
using namespace std;

#include <iostream>
#include <ostream> // this should be fstream

int main ( ) {
ofstream Myfile;
Myfile.open ("example.txt");
Myfile << "Piet is gek\n";
Myfile.close ();
return 1;
}
Stupid question. I am sorry. ! problem solved. Thanks a lot.

Nieuwenhuizen
T13:15
Topic archived. No new replies allowed.