내일배움캠프-언리얼

[내일배움캠프 - 언리얼] DAY 24 - 텍스트 콘솔 RPG - 2

이시보 2025. 12. 31. 21:08

try-catch로 입력 받은 값 검사

string select;
cin >> select;
int a = -1;
try {
    a = stoi(select);
}
catch (const std::invalid_argument& e) {
    cout << "\033[1;31m" << "[Error]잘못된 입력입니다." << "\033[0m" << endl;
    continue;
}

문자열로 받은 값을 int로 변환할 때 뜰 수 있는 오류를 try-catch로 검사하였다.

 

터미널에 색깔 입히기

cout << "\033[1;30m" << "black " << "\033[0m" << endl;
cout << "\033[1;31m" << "red " << "\033[0m" << endl;
cout << "\033[1;32m" << "green " << "\033[0m" << endl;
cout << "\033[1;33m" << "yellow " << "\033[0m" << endl;
cout << "\033[1;34m" << "blue " << "\033[0m" << endl;
cout << "\033[1;35m" << "magenta " << "\033[0m" << endl;
cout << "\033[1;36m" << "cyan " << "\033[0m" << endl;
cout << "\033[1;37m" << "white " << "\033[0m" << endl;