tags:

views:

91

answers:

2

What I am trying to do here is to find right place in a file and start writing. I gave a shot with fstream and got an error saying: variable ‘std::fstream myfile’ has initializer but incomplete type

the code I declare it is:

fstream myfile(FILENAME, ios::in|ios::out);

any comments? Or there is better way to handle this? thanks

A: 

You need to include the appropriate header file -- <fstream>.

dirkgently
This is something confusing me now. I also includes another class which includes <fstream>. For some reason, i got errors when I tried to include the <fstream> in my main function.
small_potato
@small_potato: and what errors were those? We can't see your screen from here.
Greg Hewgill
the error is something like this:/tmp/ccipcc4D.o: In function `main':grow_building.cpp:(.text+0x59): undefined reference to `std::basic_fstream<char, std::char_traits<char> >::basic_fstream(char const*, std::_Ios_Openmode)'grow_building.cpp:(.text+0x65): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()'grow_building.cpp:(.text+0x71): undefined reference to `std::basic_fstream<char, std::char_traits<char> >::is_open()'there are more, but I guess I can't put here...
small_potato
you could edit them into your question ;)
jalf
are you using `using namespace std;` in your code?
The Elite Gentleman
+1  A: 

These errors:

/tmp/ccipcc4D.o: In function `main': 
grow_building.cpp:(.text+0x59): undefined reference to `std::basic_fstream<char, std::char_traits<char> >::basic_fstream(char const*, std::_Ios_Openmode)'
grow_building.cpp:(.text+0x65): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()'
grow_building.cpp:(.text+0x71): undefined reference to `std::basic_fstream<char, std::char_traits<char> >::is_open()'

mean you are not linking with the standard C++ library.

Assuming you are using gcc, you need to use g++ instead of gcc for your link statement.

R Samuel Klatchko