C++ Toast
[C++] 한 라인에 ';'으로 5개의 이름을 구분하여 입력받아, 각 이름을 끊어내어 화면에 출력하여라
by 하루한번토스트
2024. 7. 23.
실행 예시
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main() {
string inputedName;
string name[5];
cout << " 5 명의 이름을 ';'으로 구분하여 입력하세요 " << endl;
cout << ">>";
getline(cin,inputedName);
stringstream ss(inputedName);
string token;
int index = 0;
while (getline(ss, token, ';') && index < 5) {
name[index] = token;
index++;
}
cout << "입력된 이름들:\t";
for (int i = 0; i < 5; i++) {
cout << name[i] << '\t';
}
}