vc 中使用string

来源:百度知道 编辑:UC知道 时间:2024/05/13 15:50:01
我在accelereted c++中看到这个示例程序 ,但是自己编写时却发生错误,无法运行,请各位帮忙看看问题到底在哪里
第一次没使用名字空间,貌似vc6.0 不用名字空间
#include<iostream.h>
#include<string.h>
//using namespace std
void main()
{
cout<<"please enter your name"<<endl;
string name;
cin>>name;
cout<<"hello,"<<name<<"!"<<endl;
}
错误提示如下
F:\display\05.cpp(7) : error C2065: 'string' : undeclared identifier
F:\display\05.cpp(7) : error C2146: syntax error : missing ';' before identifier 'name'
F:\display\05.cpp(7) : error C2065: 'name' : undeclared identifier
看上去应该是无法这样定义 但是书上却是这样的。。
用了名字空间之后,也有三个错误,到底是怎么回事?

#include<iostream.h>
#include<string.h>
using namespace std ;
void main()
{
cout<<"please enter your name"<<endl;
string name;
cin>>name;
cout<<"hello,"<<name<<"!"<<endl;
}

可以用:
#include<iostream>
#include<string>
using namespace std;

void main()
{
cout<<"please enter your name"<<endl;
string name;
cin>>name;
cout<<"hello,"<<name<<"!"<<endl;
}
把.h去掉的