开发者

how to write and read a file at same time

开发者 https://www.devze.com 2022-12-22 00:11 出处:网络
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 say开发者_如何学运维ing:variable ‘std::fstream myfile’ has initializer but

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 say开发者_如何学运维ing: 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


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消