简单问题
//main.cpp
//~
#include "iostream.h"
#include "string.h"
using namespace std;
int main()
{
string user_name;
cin >> user_name;
cout << end
<< user_name;
return 0;
}
编译时出现如下错误:
--------------------configuration: cin - win32 debug--------------------
compiling...
cin.cpp
f:\源代码\c\cin.cpp(7) : error c2871: std : does not exist or is not a namespace
f:\源代码\c\cin.cpp(11) : error c2065: string : undeclared identifier
f:\源代码\c\cin.cpp(11) : error c2146: syntax error : missing ; before identifier user_name
f:\源代码\c\cin.cpp(11) : error c2065: user_name : undeclared identifier
f:\源代码\c\cin.cpp(14) : error c2065: end : undeclared identifier
error executing cl.exe.
cin.exe - 5 error(s), 0 warning(s)
推荐阅读
应该是这样的:
#include "iostream"
#include "string"
using namespace std;
int main()
{
string user_name;
cin >> user_name;
cout << endl
<< user_name;
return 0;
}
用using namesapce std后就不用在头文件上加.h了.
//main.cpp
//~
#include <iostream>
#include <string>
using namespace std;
int main()
{
string user_name;
cin >> user_name;
cout << endl<< user_name <<endl;
return 0;
}
//main.cpp
//~
#include "iostream"
#include "string"
using namespace std;
int main()
{
string user_name;
cin >> user_name;
cout << endl
<< user_name;
return 0;}
同意楼上,这是c语言为了兼容以前的程序而作的修改。
一般情况下加不加.h是一模一样的,但是iostream就偏有这么个古怪的个性。
wangweintk(枫杨) 建议你多研究一下标准c++;你这不是误人子弟嘛
这样试一下也许会好一些
//main.cpp
//~
#include "iostream.h"
#include "string"
using namespace std;
int main()
{
string user_name;
cin >> user_name;
cout << endl<< user_name;
return 0;
}


讨论区