【发布时间】:2010-03-01 16:03:21
【问题描述】:
我在这里要做的是在文件中找到正确的位置并开始编写。我用 fstream 试了一下,得到一个错误提示:变量“std::fstream myfile”有初始化程序但类型不完整
我声明的代码是:
fstream myfile(FILENAME, ios::in|ios::out);
有没有cmets?或者有更好的方法来处理这个?谢谢
【问题讨论】:
标签: c++
我在这里要做的是在文件中找到正确的位置并开始编写。我用 fstream 试了一下,得到一个错误提示:变量“std::fstream myfile”有初始化程序但类型不完整
我声明的代码是:
fstream myfile(FILENAME, ios::in|ios::out);
有没有cmets?或者有更好的方法来处理这个?谢谢
【问题讨论】:
标签: c++
这些错误:
/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()'
表示您没有链接到标准 C++ 库。
假设您使用的是 gcc,您的链接语句需要使用 g++ 而不是 gcc。
【讨论】:
您需要包含适当的头文件 -- <fstream>。
【讨论】:
main': grow_building.cpp:(.text+0x59): undefined reference to std::basic_fstreamstd::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()' grow_building.cpp:(.text+0x71): undefined reference to std::basic_fstream