首席需要用到fstream头文件,然后用ifstream就可以了。
我给lz写一个例子,lz看一下就明白了:
strcut
stocktype
{
string
personaddress;
string
personcity;
string
personstate;
int
personzip;
};
void
addresstype
::
getdata()
{
ifstream
infile;
int
index;
string
inputfile;
stocktype
addresstypelist[no_of_person];
cout<<"enter
the
file
path:
";
cin>>inputfile;
//输入txt文件路径
cout<
>addresstypelist[index].personaddress;
infile>>addresstypelist[index].personcity;
infile>>addresstypelist[index].personstate;
infile>>addresstypelist[index].personzip;
}
}