原始代码class.cpp:
#include <stdio.h>
#include <string.h>
#include <iostream.h>
int main(int argc, char **argv)
{
class stud {
private:
int num;
char name[10];
char sex;
public:
stud() {
num = 1010;
strcpy(name, "xiongfeng");
sex = 'm';
} void display() {
cout << "num:" << num << endl;
cout << "name:" << name << endl;
cout << "sex:" << sex << endl;
}
};
stud stud1;
stud1.display();
return 0;
}
编译:g++ class.cpp -Wall
出现的警告:
g++ class.cpp -Wall
In file included from /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/backward/iostream.h:31,
from class.cpp:3:
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
解决方法:
将头文件#include <iostream.h>改为#include <iostream>,并在下一行加上using name space std; 其原因我在网上找了下,有些网友这样说:
1、iostream.h是旧的头文件了,iostream里使用了namespace,支持C99标准
2、. h格式的头文件早在98年9月份就被标准委员会抛弃了,我们应该紧跟标准,以适合时代的发展。
3、其次,iostream.h只支持窄字符集,iostream则支持窄/宽字符集。
4、标准对iostream作了很多的改动,接口和实现都有了变化。
5、iostream组件全部放入namespace std中,防止了名字污染。
仅供参考。
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
int main(int argc, char **argv)
{
class stud {
private:
int num;
char name[10];
char sex;
public:
stud() {
num = 1010;
strcpy(name, "xiongfeng");
sex = 'm';
} void display() {
cout << "num:" << num << endl;
cout << "name:" << name << endl;
cout << "sex:" << sex << endl;
}
};
stud stud1;
stud1.display();
return 0;
}
编译:g++ class.cpp -Wall 这样改后编译就没警告出现了!
运行:. /a.out
结果:
num:1010
name:xiongfeng
sex:m
--
/**************************************/
Name: Xiong Feng
E-mail:linux0818@gmail.com
MSN:linux0818@hotmail.com
QQ:23562033
Address: GuangZhou.China
/**************************************/
没有评论:
发表评论