1. 程式人生 > >讀取電話號碼

讀取電話號碼


#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; }