我是C++編程新手,對矢量大小和循環有疑問。如何遍歷矢量大小C++
比方說,我的矢量大小是由值3:
x = [Susan 13, Female, Chicago Illinois] //this will be the comparison point
y = [Sally 18, Female, Tokyo Japan]
z = [Rowland 2, Male, Arizona California] //y & z will be compared to x
+...other vectors depending on how many the user inputs
我想創建一個for循環,會由y &ž比較X生成每個年齡段的。所以,我希望它像
x[0] - y[0] --> 5 //difference of the ages
x[0] - z[0] --> 11
到目前爲止,我有這樣的:
vector<string> age, gender, location;
void ageDiff(vector<string> a, vector<string> g, vector<string> l){
//i want to start calculating the age differences but i'm not sure how to loop depending on how many data the user inputs
}
int main(){
int n;
std::cout << "How many data will you input? ";
std::cin >> n;
for (a=0;a<n;a++){
std::cout << "Please enter the data for person #" << a;
std::cin >> a;
std::cin >> b;
std::cin >> c;
age.push_back(a);
gender.push_back(b);
location.push_back(c);
for (a=0;a<(age.size()-1);a++){
ageDiff(age, gender, location)
}
採用矢量 {INT年齡;字符串名稱;字符串位置...}然後載體,再加上正確的是什麼,以及如何你:在它的創建人
people
和環矢量想要比較和你試圖實現什麼 – qwr