热情软件屋

 

编译错误:must use C++ for the type iostream


编号:QA000735
建立日期: 1999年3月31日 最后修改日期:1999年3月31日
所属类别:

王全:
    Borland C++4.5
    windows98
    我遇到的问题是:
    我在编译源文件时,提示错误为:
    fatal ..\BC45\include\iostream.h 24:Error directive:must use C++ for the type iostream.这是让我定义__cplusplus,但我定义后出现里更多的错误,不知是什么原因,恳请指点迷津。谢谢?
    #ifndef __colusplus
    #define __cplusplus //如何定义?在什么地方定义?
    #include
    #include
    #include
    
    typedef float Real;
    
    extern Real ran1(int*);
    extern Real ran1(int newseed);
    extern Real ran1();
    extern Real ran1(int* idum);
    
    #include "Ranges.h"
    #include "Citizen.h"
    #include "Population.h"
    // //main
    //
    int main()
    {
    ......(省略,太长)
    }
    问题是:在编译源文件时,如果不定义了第一行和第二行,则提示错误为:
    fatal ..\BC45\include\iostream.h 24:Error directive:must use C++ for the type iostream.
    果定义了第一行和第二行,则提示错误为:
    1.Error ..\BC45\include\mem.h 37:Declaration terminated incorrectly
    2.Error ..\BC45 include\IOStream.h 71:Declaration syntax error
    3...(共26个错误)

回答:

    我想你的文件的扩展名一定是.c,而不是.cpp。一般C++编译器对.c文件使用C方式编译,对.cpp文件使用C++方式编译(编译器会自动定义__cplusplus)。而C++的I/O流只能在C++编译方式下工作。所以简单的办法是改文件扩展名为.cpp。如果你一定要采用#define的办法,你的程序中少了#endif,应该这样:
    #ifndef __cplusplus
    #define __cplusplus //如何定义?这样定义!
    #endif

此问题由李海回答。

 
把这个问题推荐给朋友
   
   
您的意见类别
您的名字
您的电子邮件
您的建议(请尽可能详细)
 
 

版权所有 1997-2008 热情软件屋
如果您有任何建议和意见, 请给我发个电子邮件 askpro@china-askpro.com
Web Designed by ZebraStudio