C++ 怎么定义一个string类变量?
新建了一个空DOS工程 写下如下代码:
#include "iostream.h"
#include "conio.h"
#include "string.h"
int main(){
string s = "Hello!";
cout<<s<<endl;
getch();
return 0;
}
保存为test1.cpp
编译后报错 :
test1.cpp
...\test1\test1.cpp(8) : error C2065: 'string' : undeclared identifier
...\test1\test1.cpp(8) : error C2146: syntax error : missing ';' before identifier 's'
...\test1\test1.cpp(8) : error C2065: 's' : undeclared identifier
...\test1\test1.cpp(8) : error C2440: '=' : cannot convert from 'char [7]' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
Error executing cl.exe.