你好,我想请教怎么样C++从两个文件中分别读取十个复数存到两个数组中

2024-11-08 21:42:03
推荐回答(1个)
回答(1):

首席需要用到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<
infile(inputFile.c_str()); //infile按照指定路径读取txt文件

for(index = 0; index < NO_OF_PERSON; index++)//读取txt文件至struct
{
infile>>addressTypeList[index].personAddress;
infile>>addressTypeList[index].personCity;
infile>>addressTypeList[index].personState;
infile>>addressTypeList[index].personZIP;
}
}