Win7下装的VC6.0显示的已经安装成功,但运行起来总出现问题?

当包含的文件不加.h,但加命名空间std时,如下
#include <iostream>
#include <string>
using namespace std;
......
出现错误提示:
error C2504: 'exception' : base class undefined
error C2556: 'void __cdecl main(void)' : overloaded function differs only by return type from 'int __cdecl main(void)'
c:\program files\microsoft visual studio\vc98\include\new(2) : see declaration of 'main'
error C2371: 'main' : redefinition; different basic types
error C2872: 'cout' : ambiguous symbol
error C2872: 'cin' : ambiguous symbol
error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable conversion)
error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable conversion)
......
大概这样,这时好像不支持std

当都加上.h时
#include <iostream.h>
#include <string.h>
......
这时也报错
error C2146: syntax error : missing ';' before identifier 'replace'
error C2501: 'string' : missing storage-class or type specifiers
fatal error C1004: unexpected end of file found
好像不识别string.h,可我已经在tools->options->Directory中添加了有关的项了

这时怎么回事呀?似乎是安装有问题?不管怎样,我也重装过好几次VC了,但总是这个反应,请教哪位高手给分析分析?
简化了,依旧出现上述问题
#include <iostream.h>
#include <string.h>
int main()
{
string sub;
cout<<"sub串:"<<endl;
cin>>sub;
cout<<sub<<endl;
return 0;
}

Compiling...
c++.cpp
c++.cpp(5) : error C2065: 'string' : undeclared identifier
c++.cpp(5) : error C2146: syntax error : missing ';' before identifier 'sub'
c++.cpp(5) : error C2065: 'sub' : undeclared identifier
Error executing cl.exe.

syntax error : missing ';' before identifier 'replace'
这句意思是差标点','逗号,
fatal error C1004: unexpected end of file found
这句是没找到程序结束,在最后某处少了'}'花括号。
error C2501: 'string' : missing storage-class or type specifiers
除了需要包含string外还需要设置命名空间
using namespace std
string后面不加h,我也是win7每次运行都弹出不兼容的对话框,但程序还是能编译出来
并通过。还有疑问百度hi我 可以把你源程序发过来 我看下
温馨提示:内容为网友见解,仅供参考
第1个回答  2011-11-01
用你简化了的代码编译了下也出现了同样的问题,然后我将代码改成了下面这样:

#include <iostream>
#include <string>
using namespace std;

int main()
{
string sub;
cout<<"sub串:"<<endl;
cin>>sub;
cout<<sub<<endl;
return 0;
}

结果编译是通过的,程序能正常运行。我用的是win7旗舰版64位的操作系统
相似回答