저는 C++ 프로그래밍을 처음 접했고 벡터 크기와 for 루프에 대해 질문이 있습니다.벡터 크기를 반복하는 방법 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
내가 X에 Y & Z를 비교하여 연령의 각을 생성 루프를 만들려고합니다. 그래서
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)
}
사용 벡터을 나이, 또는 더 나은 구조체 dataunit에 대한 {INT 연령, 문자열 이름을, 문자열 위치 ...} 다음 벡터 , 플러스 올바른을 무엇을 어떻게 당신을 compare.and을 얻으 려합니다. –
qwr