c++ - 在 c++builder 中编译 c++ 的问题

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

我为一项大学作业编写了一个 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 <string>

它是:

#include <windows.h>

虽然我怀疑你需要它。

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

If you use a class or a function, always explicitly #include the header for that class or function in your code.

关于c++ - 在 c++builder 中编译 c++ 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2461977/

相关文章:

c++ - 增量构建 : Eclipse CDT does not notice that source has changed

c++ - 在 C++11 中,sqrt 定义为 constexpr?

c++ - 尝试使用新构造函数和复制构造函数分配内存时获取 "expected unqualified-id before ‘(’ token

components - 如何备份我的 C++ Builder 组件安装?

c++ - 为什么我必须为 QFileDialog 指定父级

C++ 模板 sfinae 错误

xcode - Xcode无法识别C++语法

java - 我尝试运行这段代码,它运行时不会抛出错误,问题是它不会执行 for 循环我只是一个初学者,所以请

c++ - 将静态成员的范围限制为 n 个特定类

c++builder - 项目迁移后 Unresolved external 问题