【问题标题】:how to write and read a file at same time如何同时写入和读取文件
【发布时间】:2010-03-01 16:03:21
【问题描述】:

我在这里要做的是在文件中找到正确的位置并开始编写。我用 fstream 试了一下,得到一个错误提示:变量“std::fstream myfile”有初始化程序但类型不完整

我声明的代码是:

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

有没有cmets?或者有更好的方法来处理这个?谢谢

【问题讨论】:

    标签: c++


    【解决方案1】:

    这些错误:

    /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。

    【讨论】:

      【解决方案2】:

      您需要包含适当的头文件 -- &lt;fstream&gt;

      【讨论】:

      • 这让我很困惑。我还包括另一个包含 的类。出于某种原因,当我尝试在主函数中包含 时出现错误。
      • @small_potato:那些错误是什么?我们无法从这里看到您的屏幕。
      • 错误是这样的: /tmp/ccipcc4D.o: In function main': grow_building.cpp:(.text+0x59): undefined reference to std::basic_fstream >::basic_fstream(char const*, std::_Ios_Openmode)' grow_building.cpp:(.text+0x65): undefined reference to std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;::basic_string()' grow_building.cpp:(.text+0x71): undefined reference to std::basic_fstream >::is_open()' 还有更多,但我我猜我不能放在这里...
      猜你喜欢
      • 1970-01-01
      • 2013-12-17
      • 1970-01-01
      • 1970-01-01
      • 2019-07-14
      • 2010-10-10
      相关资源
      最近更新 更多