#include <fstream>
#include <string>
#include <vector>
#include <iostream>
#include <sstream>//istringstream
using namespace std;//string
struct PersonInfo {
string name;
vector<string> phones;
};
int main()
{
ifstream input("test.txt");
string line, word;
vector<PersonInfo> people;
while (getline(input, line))
{
PersonInfo info;
istringstream record(line);//把line当做字符串付给record,record再对行进行处理
record >> info.name;
while (record >> word)
info.phones.push_back(word);
people.push_back(info);
}
input.close();
for (int i = 0; i < people.size(); i++)
{
cout << people[i].name<<"," << people[i].phones[i] << endl;
}
getchar();
return 0;
}
读取电话号码
猜你喜欢
转载自blog.csdn.net/Claire_ll/article/details/84970819
今日推荐
周排行