在c ++ builder中编译c ++问题 [英] Issue compiling c++ in c++builder

查看:260
本文介绍了在c ++ builder中编译c ++问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  [BCC32错误] main.cpp(51):E2094'operator'<'not in type'ostream'for arguments of type'string'
[BCC32 Error] main.cpp(62):E2093'operator =='对于同类型的参数,不能在类型'string'中实现
[BCC32 Error] main.cpp(67):E2093'operator =='在类型'string' b [BCC32错误] main.cpp(112):E2093'operator =='未在类型'string'中实现同类型的参数
[BCC32 Error] main.cpp(121):E2094'operator<对于类型'string'的参数,''''类型''''''实现
[BCC32错误] main.cpp(130):E2093'operator =='类型
[BCC32错误] main.cpp(133):E2094'操作符<<'不能在类型'ostream' ):E2094'operator'<'not in type'ostream'for type of'string'
[BCC32 Error] main.cpp(153):E2094'operator<类型为'string'的参数没有实现$ f
[bcc32 Error] main.cpp(199):E2094'operator> BCC32 Error] main.cpp(219):E2094'operator>>'在类型'istream'中不实现类型'string'的参数
[BCC32 Error] main.cpp(231) >''''类型的参数的类型'istream'中实现
[BCC32错误] main.cpp(240):E2094'操作符> 'string'
[BCC32错误] main.cpp(262):E2094'操作符>>'未在类型'istream' (264):E2094'operator>>'未在类型'istream'中实现类型'string'的参数


$ b b




这些是我使用

的头文件

  #include< iostream> 
#include< fstream>
#include< cmath>
#include< stdio>
#include< windows> //我添加这个只是为了检查,仍然不工作(我没有在Netbeans / Mac)
using namespace std;






任何想法都会产生错误,


解决方案

您需要:

  #include< string> 

,它是:

  #include< windows.h> 

虽然我怀疑你需要它。



您的代码在一个平台而不是另一个平台上工作的原因是,在第一个平台上,其他库头文件中包含< string> 本身。这个行为没有被C ++标准规定,所以唯一安全的规则是:


如果你使用类或函数,
总是显式地在
代码中包含该类或函数的标头



I have written a C++ program for a University assignment. I used Netbeans 6.8 running on my Mac and the code runs smoothly, no warnings, errors or problems/bugs. However when compiling and running on a Windows computer using CodeGear RAD Studio 2009 (C++ Builder) am getting several errors.

[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. This behaviour is not specified by the C++ Standard, so the only safe rule is:

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

这篇关于在c ++ builder中编译c ++问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆