我從結構中創建了一個向量來存儲多種類型的值。但是,我無法獲得投入。類不支持運算符
#include "std_lib_facilities.h"
struct People{
string name;
int age;
};
int main()
{
vector<People>nameage;
cout << "Enter name then age until done. Press enter, 0, enter to continue.:\n";
People name;
People age;
while(name != "0"){
cin >> name;
nameage.push_back(name);
cin >> age;
nameage.push_back(age);}
vector<People>::iterator i = (nameage.end()-1);
nameage.erase(i);
}
我也試過在其主函數的名字和年齡變量是字符串/ int型,雖然能解決操作問題,它導致了一個問題,在該行的push_back函數調用。
P.S.是否有可能push_back多個輸入,如...
cin >> name >> age;
nameage.push_back(name,age);
?
你會得到哪些錯誤? – jalf 2009-07-10 17:49:05