c++ - g++ 中的 fstream 链接错误与 -std=gnu++0x

标签 c++ g++ c++11 tdm-mingw

我在 Windows 上的 tdm-mingw g++ 4.4.0 中使用 -std=gnu++0x 参数构建了一个应用程序。

它使用的是 ofstream 对象,当我构建时,它给出了以下链接错误:

c:\opt\Noddler/main_func.cpp:43: undefined reference to `std::basic_ofstream<char, std::char_traits<char> >::basic_ofstream(std::string const&, std::_Ios_Openmode)'

它在使用默认的旧标准时正确构建。

这是唯一的错误,尝试与 -lstdc++ 链接没有帮助。有人以前经历过吗?我可以得到任何建议吗?

编辑: 我正在创建这样一个 ofstream 对象:

std::string filename = string("noddler\\") + callobj.get_ucid() + "_" + callobj.gram_counter() + ".grxml";
ofstream grxml_file(string("C:\\CWorld\\Server\\Grammar\\") + filename);
...
grxml_file.close();

编译正常,但没有链接。

最佳答案

我猜你有这样的代码:

string fname = "foo.txt";
ifstream ifs( fname );

尝试将其更改为:

ifstream ifs( fname.c_str() );

如果您使用的头文件与您链接到的库有些不协调,则可能会发生这种情况。如果这不起作用,请发布导致问题的代码。

关于c++ - g++ 中的 fstream 链接错误与 -std=gnu++0x,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1165071/

相关文章:

c++ - 每个用户的注册表值

c++ - 编写一个转储屏幕像素的 RDP 客户端

c++ - 静音 gcc 的 "only available with -std=c++XX or -std=gnu++XX"警告

c++ - 你最喜欢的 g++ 选项是什么?

c++ - 是否可以在 C++ 中使用 "bundle"模板参数?

c++ - 使用 SAX2 时如何在 Xerces-C 中获取 Doctype 声明?

c++ - 如果对象具有私有(private)复制构造函数,为什么我不能初始化对象数组?

c++ - 使用 C++11 线程对非常量引用进行无效初始化?

c++ - 没有 RTTI 的 shared_ptr?

c++ - 函数未在范围内声明 (C++)