#include<iostream.h>
#include<string.h>
using namespace std;
int main()
{
string user_name;
cout<<"please enter your first name:";
cin>>user_name;
cout<<'\n'
<<"Hello,"
<<user_name
<<"...and goodbye!\n";
return 0;
}--------------------Configuration: 01 - Win32 Debug--------------------
Compiling...
101.cpp
e:\我的文件夾\vc++\01\101.cpp(3) : error C2871: 'std' : does not exist or is not a namespace
e:\我的文件夾\vc++\01\101.cpp(6) : error C2065: 'string' : undeclared identifier
e:\我的文件夾\vc++\01\101.cpp(6) : error C2146: syntax error : missing ';' before identifier 'user_name'
e:\我的文件夾\vc++\01\101.cpp(6) : error C2065: 'user_name' : undeclared identifier
Error executing cl.exe.01.exe - 4 error(s), 0 warning(s)using namespace std;我還是不清楚
#include<string.h>
using namespace std;
int main()
{
string user_name;
cout<<"please enter your first name:";
cin>>user_name;
cout<<'\n'
<<"Hello,"
<<user_name
<<"...and goodbye!\n";
return 0;
}--------------------Configuration: 01 - Win32 Debug--------------------
Compiling...
101.cpp
e:\我的文件夾\vc++\01\101.cpp(3) : error C2871: 'std' : does not exist or is not a namespace
e:\我的文件夾\vc++\01\101.cpp(6) : error C2065: 'string' : undeclared identifier
e:\我的文件夾\vc++\01\101.cpp(6) : error C2146: syntax error : missing ';' before identifier 'user_name'
e:\我的文件夾\vc++\01\101.cpp(6) : error C2065: 'user_name' : undeclared identifier
Error executing cl.exe.01.exe - 4 error(s), 0 warning(s)using namespace std;我還是不清楚
你去掉就好拉
//#include<string.h>//using namespace std; 什么意思?int main()
{
char user_name[10];
cout<<"please enter your first name:";
cin>>user_name;
cout<<'\n'
<<"Hello,"
<<user_name
<<"...and goodbye!\n";
return 0;
}
如果你使用的是标准C++,那么用后者;如果你使用微软提供的,那么用前者。
使用后者时,你就需要使用using namespace std
使用前者时,因为你没有定义std namespace,所以无法编译通过
#include <string.h>改为标准库头文件:
#include <iostream>
#include <string>
#include <string.h>中没有命名空间std的定义,所以会出现错误提示,它的定义在
#include <iostream>
#include <string>中,此外string 的定义在<string>中,而不是<string.h>中,
<stirng.h>中定义的是strcpy 等C的字符串操作函数
#include <string.h>中没有命名空间std的定义,所以会出现错误提示,它的定义在
#include <iostream>
#include <string>中,此外string 的定义在<string>中,而不是<string.h>中,
<stirng.h>中定义的是strcpy 等C的字符串操作函数