vector 질문입니다. 고수님들 두뇌좀 나눠주십시요.
모해
첨부한 파일은 제가 만들어야 하는 코드의 가이드와 완성되어있는 견본입니다.
제가 작업한 코드는 아래와 같습니다.
제가 input.txt 파일을 받아서 cmd 창에 입력된 정보를 띄우는데까지는 문제가 없는것 같습니다.하지만 가장 나이가 많은사람과 가장 나이가 적은사람이 맞지가 않는것 같은게 첫번째 문제이고
두번째는 첨부된 .exe 실행파일처럼 값을 입력하는 방법을 전혀모르겠습니다.
고수님들의 조언 감사히 받들겟습니다./* Assignment3.cpp To solve the problem about the vector Algorithm from an assignment. Written by Kyungman Kim Date October 5th*/#include iostream#include algorithm#include vector#include string#include iterator#include iomanip#include utility
using namespace std;
bool compare(const pairstring, int&i, const pairstring, int&j){ return i.first j.first;}
int main(void){ cout Enter a first name and an age (use - for a name when you are done) endl; cout Name: ; string Name; int Age = 0; vectorpair string, int myVector; vectorpair string, int ::iterator pos; //Iterator for vector pair
cin Name Age;
while(Name != -){ myVector.push_back(make_pair(Name,Age));
cin Name Age; } // Sorting name by Alphabetically sort (myVector.begin(), myVector.end()); for(pos = myVector.begin(); pos myVector.end(); ++pos){ cout pos-first pos-second endl; }
cout endl;
// to get the youngest person and oldest person. sort(myVector.begin(), myVector.end(), compare); cout The youngest person is: myVector.begin()-first endl; cout The oldest person is: (--myVector.end())-first endl;
system(pause); return 0;}