//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)

解决方案 »

  1.   

    using namespace std;是什么意思,定义出错,把这行去掉。string应改为CString。估计,你是在那本书上抄下的代码,这本书太次了。
      

  2.   

    应该是这样的:
    #include "iostream"
    #include "string"using namespace std;int main()
    {
    string user_name;
    cin >> user_name;
    cout << endl
     << user_name;
    return 0;
    }
      

  3.   

    用using namesapce std后就不用在头文件上加.h了.
      

  4.   

    //main.cpp
    //~#include <iostream>
    #include <string>using namespace std;int main()
    {
    string user_name;
    cin >> user_name;
    cout << endl<< user_name <<endl;
    return 0;
    }
      

  5.   

    //main.cpp
    //~#include "iostream"
    #include "string"
    using namespace std;int main()
    {
    string user_name;
    cin >> user_name;
    cout << endl
    << user_name;
    return 0;}
      

  6.   

    同意楼上,这是c语言为了兼容以前的程序而作的修改。
    一般情况下加不加.h是一模一样的,但是iostream就偏有这么个古怪的个性。
      

  7.   

    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;
    }
      

  8.   


    "string.h"改为"string"
    另外最好在它前面加上#pragma warning (disable : 4786)
    否则编译会出一堆warning,虽然不影响使用,但看着碍眼