当包含的文件不加.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.