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