简体   繁体   English

在C ++ Builder中发布C ++的问题

[英]Issue compiling c++ in c++builder

I have written a C++ program for a University assignment. 我已经为大学作业编写了一个C ++程序。 I used Netbeans 6.8 running on my Mac and the code runs smoothly, no warnings, errors or problems/bugs. 我使用了在Mac上运行的Netbeans 6.8,并且代码运行流畅,没有警告,错误或问题/错误。 However when compiling and running on a Windows computer using CodeGear RAD Studio 2009 (C++ Builder) am getting several errors. 但是,当使用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'

These are the header files am using 这些是我正在使用的头文件

#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;

Any ideas what is producing the errors and how can I fix it? 有什么想法会导致错误,如何解决?

You need: 你需要:

#include <string>

and it's: 它是:

#include <windows.h>

though I doubt you need it. 尽管我怀疑您是否需要它。

The reason your code worked on one platform but not another is that on the first platform one of the other library headers was including <string> itself. 您的代码可以在一个平台上运行而不是在另一个平台上运行的原因是,在第一个平台上,其他库头文件之一包含<string>本身。 This behaviour is not specified by the C++ Standard, so the only safe rule is: C ++标准未指定此行为,因此唯一安全的规则是:

If you use a class or a function, always explicitly #include the header for that class or function in your code. 如果您使用类或函数,请始终在代码中明确#include该类或函数的头。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM