一个小问题

来源:互联网 发布:访客网络 编辑:程序博客网 时间:2024/05/14 05:28

今天写了一个小程序,编译时总是出现以下错误提示:

error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class __SMANIP_int' (or there is no acceptable conversion)

调试了好久,就是找不出问题在哪。

后来,终于找到问题所在:原来是头文件的问题。

我的程序中包含了

#include <iostream.h>
#include <string>
#include <iomanip.h>

解决方法:将头文件中的.h去掉,并加上using namespace std;即头文件改为:

#include <iostream>
#include <string>

#include <iomanip>

using namespace std;

这样,就OK了。顺利编译通过。

两者的区别:

#include<iostream.h>是在旧的标准C++中使用。在新标准中,用#include<iostream>。

#include<iostream>是标准的C++头文件,任何符合标准的C++开发环境都有这个头文件。注意:在编程时一定要添加:using namespace std;

使用<iostream.h>时,相当于在C中调用库函数,使用的是全局命名空间,也就是早期的C++实现;

使用<iostream>时,该头文件没有定义全局命名空间,必须使用 namespace std;


原创粉丝点击