请C++高手指教
最近刚学C++,在调用string类的时候出错,例如下面的程序:
#include <iostream.h>
#include <string.h>
void mian()
{string p1= "hello ";
cout < <p1 < <endl;
}
出错信息为:
Compiling...
test.cpp
f:\test\test.cpp(5) : error C2065: 'string ' : undeclared identifier
f:\test\test.cpp(5) : error C2146: syntax error : missing '; ' before identifier 'p1 '
f:\test\test.cpp(5) : error C2065: 'p1 ' : undeclared identifier
f:\test\test.cpp(5) : 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.
test.obj - 4 error(s), 0 warning(s)
应该是没有加载string头文件的缘故,但明明已经写了include语句,请大家指教下。
[解决办法]
#include <iostream>
#include <string>
using namespace std;