如何在头文件中定义string类型

来源:百度知道 编辑:UC知道 时间:2024/05/31 19:39:53
如题
//System.h=======================
string c;
//main.cpp=======================
#include"System.h"
#include<iostrem>
using namespace std;

void main ()
{ cin>>c;}

编译错误:
g:\SYSTEM.h(3) : error C2146: syntax error : missing ';' before identifier 'c'
g:\SYSTEM.h(3) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
g:\SYSTEM.h(3) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

这些是什么意思呀?
加过<string>;<string.h>还是一样不行
我用的是Microsoft Visual Studio 2005
最好举个例子来参考下

string是标准库std里的一种数据类型,在程序开始加上#include<string>即可定义;
参考实例如下:
#ifndef head_h
#define head_h
#include <string>
using namespace std;
#define Max 3
#define Charge 5
class Car_Park
{
private:
string carname ;
string carnum;
};
#endif

string是标准库std里的一种数据类型,所以你必须先用using namespace再定义string数据类型
#include<iostream>
#include<string>
using namespace std;
string c;
int main(){
cin>>c;

}

这样就可以了

最开头加上
#include<string>
即可

string 不明白!我用了很长时间VC了 一直在用CString 用这个好点!