注册 登录
编程论坛 C++教室

[讨论]关于头文件写法的疑惑

freshman42 发布于 2006-04-26 21:54, 1496 次点击

#include<iostream.h>

#include<iostream>
using namespace std;
这两种写法我以前用都可以的 可是最近不知道为什么我用前面的那中写法 老是会出现以下的错误提示
d:\microsoft visual studio\vc98\include\streamb.h(90) : error C2027: use of undefined type 'ios'
d:\microsoft visual studio\vc98\include\streamb.h(67) : see declaration of 'ios'
d:\microsoft visual studio\vc98\include\streamb.h(90) : error C2061: syntax error : identifier 'seek_dir'
d:\microsoft visual studio\vc98\include\istream.h(64) : error C2504: 'ios' : base class undefined
d:\microsoft visual studio\vc98\include\istream.h(118) : error C2027: use of undefined type 'ios'
d:\microsoft visual studio\vc98\include\streamb.h(67) : see declaration of 'ios'
d:\microsoft visual studio\vc98\include\istream.h(118) : error C2061: syntax error : identifier 'seek_dir'
d:\microsoft visual studio\vc98\include\istream.h(118) : error C2535: 'class istream &__thiscall istream::seekg(long)' : member function already defined or declared
d:\microsoft visual studio\vc98\include\istream.h(117) : see declaration of 'seekg'
d:\microsoft visual studio\vc98\include\istream.h(140) : error C2664: 'class ios &(class ios &)' : cannot convert parameter 1 from 'class istream' to 'class ios &'
A reference that is not to 'const' cannot be bound to a non-lvalue
d:\microsoft visual studio\vc98\include\istream.h(155) : error C2065: 'lock' : undeclared identifier
d:\microsoft visual studio\vc98\include\istream.h(155) : error C2065: 'unlock' : undeclared identifier
d:\microsoft visual studio\vc98\include\ostream.h(59) : error C2504: 'ios' : base class undefined
d:\microsoft visual studio\vc98\include\ostream.h(95) : error C2027: use of undefined type 'ios'
d:\microsoft visual studio\vc98\include\streamb.h(67) : see declaration of 'ios'
d:\microsoft visual studio\vc98\include\ostream.h(95) : error C2061: syntax error : identifier 'seek_dir'
d:\microsoft visual studio\vc98\include\ostream.h(95) : error C2535: 'class ostream &__thiscall ostream::seekp(long)' : member function already defined or declared
d:\microsoft visual studio\vc98\include\ostream.h(94) : see declaration of 'seekp'
d:\microsoft visual studio\vc98\include\ostream.h(113) : error C2664: 'class ios &(class ios &)' : cannot convert parameter 1 from 'class ostream' to 'class ios &'
A reference that is not to 'const' cannot be bound to a non-lvalue
d:\microsoft visual studio\vc98\include\iostream.h(83) : error C2039: 'rdbuf' : is not a member of 'iostream'
d:\microsoft visual studio\vc98\include\iostream.h(66) : see declaration of 'iostream'
Error executing cl.exe.

main.obj - 15 error(s), 0 warning(s)
这是为什么呢???????

12 回复
#2
ElfDN2006-04-26 22:03

你换VC8了吧

#3
freshman422006-04-26 22:14

我用的是VC6.0

#4
吾心永恒2006-04-26 22:28

重装一下吧

总会有问题的

#5
freshman422006-04-26 22:36
不是吧 这样解决问题 那我还是用后面那种写法算了
不过那两中写法到底有没有什么区别?
它们各代表什么?
#6
激情依旧2006-04-27 11:39

I 在vc7里面是没有iostream.h这个文件的。所以你会出错。如果你在vc6.0里面,2个都是正确的。以后你用vc7的时候注意就是了

#7
静思2006-04-27 13:09
哦,原来这是版本不同所导致的呀!!!!我用的是VC6.0,所以这两种写法都可以。
#8
freshman422006-04-27 13:50
以下是引用激情依旧在2006-4-27 11:39:00的发言:

I 在vc7里面是没有iostream.h这个文件的。所以你会出错。如果你在vc6.0里面,2个都是正确的。以后你用vc7的时候注意就是了

那就怪了
我一直用的是vc6.0的最近才出现这个错误的啊,好象是从我装了.net后就出现这个问题,会不会和这有关啊

#9
wfpb2006-04-29 11:59
因为iostream.h是老板本的,现在都用iostream,
#10
krisdy2008-04-23 15:57
恩,新旧版本不通导致的问题了
新版本不再支持后缀名了
#11
cherrywang2008-04-23 20:44
是不是说没有后缀名的情况下都要用
using namespace std;啊?
用了这句话加后缀名似乎会出错的呢,呵呵
不太明白为什么。
#12
cherrywang2008-04-23 20:46
是不是说没有后缀名的情况下都要用
using namespace std;啊?
用了这句话加后缀名似乎会出错的呢,呵呵
不太明白为什么。
#13
kod_h2008-04-24 00:01
其实第二种写法才C++的标准使用方法,在该方法中要使用using namespace std;来指定使用命名空间std,如果不写这句的话,也可以在输入输出时使用如std::cin、std::cout、std::endl等形式。
LZ说的两种方法在6.0中都是可以的,但是我使用VS2005就只能使用第二种了,MS在里面作了规范。
1