关于string的问题,请高手帮忙看看

来源:百度知道 编辑:UC知道 时间:2024/06/15 17:21:47
#include <iostream.h>
#include <string.h>
void main()
{
string str="hello";
cout<<str;
}
这行程序怎么运行出错,在VC6下显示下列错误
D:\我的工作区\Derived\test.cpp(416) : error C2065: 'string' : undeclared identifier
D:\我的工作区\Derived\test.cpp(416) : error C2146: syntax error : missing ';' before identifier 'str'
D:\我的工作区\Derived\test.cpp(416) : error C2065: 'str' : undeclared identifier
D:\我的工作区\Derived\test.cpp(416) : error C2440: '=' : cannot convert from 'char [6]' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
Error executing cl.exe.

对,加上using namespace std;

iostream 和string 都是std名字空间里的

#include <iostream>
#include <string>
using namespace std;
int main()
{
string str="hello";
cout<<str;
}

#include <iostream>
using namespace std;
int main()
{
char* str="hello";
cout<<str<<endl;
}