我有問題打印出載有我的人信息的矢量。如何打印矢量類的內容
struct PersonInfo{
string name;
vector<string> phones;
};
int main(){
string line, word;
vector<PersonInfo> people;
while(getline(cin, line)){
PersonInfo info;
istringstream record(line);
record >> info.name;
while(record >> word)
info.phones.push_back(word);
people.push_back(info);
}
for(auto i = people.begin(); i != people.end(); i++)
cout << people << endl;
return 0;
}
您是否嘗試搜索所有如何在C++中打印對象?並看看你的'聲明'。如果你從不在循環體內使用它,那麼爲'vector'創建一個迭代器有什麼意義呢? – Praetorian