我有一个文本文件,其中包含一个人的 id、人名、人年龄和今天的日期。我知道如何逐行读取并溢出字符串并将其存储到向量中并打印出来。
年龄.txt
1:john:23:18-Oct-2013
2:mary:21:18-Oct-2013
3:suzy:20:18-Oct-2013
代码
ifstream readFile("age.txt");
string words;
vector<string> storeWords;
while (getline(readFile, line,':'))
{
stringstream iss(line);
while (iss >> words) {
storeWords.push_back(words);
}
}
for (int i=0; i<storeWords.size(); i++) {
cout << storeWords[i] <<endl;
}
输出
1
john
23
18-Oct-2013
2
mary
21
18-Oct-2013
3
suzy
20
18-Oct-2013
但我真的不知道如何将它们存储到数组中而不是使用向量并使其类似于
personId[] will contain all the id from the output;
personName[] will contain all the name from the output;
personAge[] will contain all the age from the output;
dateTime[] will contain all the date and time from the output;
请指教。提前致谢