【问题标题】:Issue compiling c++ in c++builder在 c++builder 中编译 c++ 的问题
【发布时间】:2010-03-17 12:00:55
【问题描述】:

我为大学作业编写了一个 C++ 程序。我使用在我的 Mac 上运行的 Netbeans 6.8 并且代码运行顺利,没有警告、错误或问题/错误。但是,当使用 CodeGear RAD Studio 2009 (C++ Builder) 在 Windows 计算机上编译和运行时,出现了几个错误。

[BCC32 Error] main.cpp(51): E2094 'operator<<' not implemented in type 'ostream' for arguments of type 'string'
[BCC32 Error] main.cpp(62): E2093 'operator==' not implemented in type 'string' for arguments of the same type
[BCC32 Error] main.cpp(67): E2093 'operator==' not implemented in type 'string' for arguments of the same type
[BCC32 Error] main.cpp(112): E2093 'operator==' not implemented in type 'string' for arguments of the same type
[BCC32 Error] main.cpp(121): E2094 'operator<<' not implemented in type 'ostream' for arguments of type 'string'
[BCC32 Error] main.cpp(130): E2093 'operator==' not implemented in type 'string' for arguments of the same type
[BCC32 Error] main.cpp(133): E2094 'operator<<' not implemented in type 'ostream' for arguments of type 'string'
[BCC32 Error] main.cpp(139): E2094 'operator<<' not implemented in type 'ostream' for arguments of type 'string'
[BCC32 Error] main.cpp(153): E2094 'operator<<' not implemented in type 'fstream' for arguments of type 'string'
[BCC32 Error] main.cpp(199): E2094 'operator>>' not implemented in type 'fstream' for arguments of type 'string'
[BCC32 Error] main.cpp(219): E2094 'operator>>' not implemented in type 'istream' for arguments of type 'string'
[BCC32 Error] main.cpp(231): E2094 'operator>>' not implemented in type 'istream' for arguments of type 'string'
[BCC32 Error] main.cpp(240): E2094 'operator>>' not implemented in type 'istream' for arguments of type 'string'
[BCC32 Error] main.cpp(262): E2094 'operator>>' not implemented in type 'istream' for arguments of type 'string'
[BCC32 Error] main.cpp(264): E2094 'operator>>' not implemented in type 'istream' for arguments of type 'string'

这些是正在使用的头文件

#include <iostream>
#include <fstream>
#include <cmath>
#include <stdio>
#include <windows> //I added this one just to check and still does not work (I didnt have it on Netbeans/Mac)
using namespace std;

任何想法是什么产生了错误,我该如何解决?

【问题讨论】:

  • 大胆猜测:你需要#include &lt;string&gt;

标签: c++ compiler-errors c++builder


【解决方案1】:

你需要:

#include <string>

它是:

#include <windows.h>

虽然我怀疑你需要它。

您的代码在一个平台上运行但在另一个平台上无法运行的原因是,在第一个平台上,其他库头文件中的一个包含&lt;string&gt; 本身。 C++ 标准未指定此行为,因此唯一安全的规则是:

如果你使用类或函数, 总是显式地#include 标头 对于你的那个类或函数 代码。

【讨论】:

    【解决方案2】:

    您可以在 string 对象上执行此操作:

    to_string < char,std::string::traits_type,std::string::allocator_type>()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-26
      • 1970-01-01
      • 1970-01-01
      • 2014-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多