Problem:

string 클래스를 이용하여 사용자가 입력한 영문 한 줄을 문자열로 입력받고 거꾸로 출력하는 프로그램을 작성하라.

Objective & Hints:

string 클래스로 문자열 다루기

Execution Result:

Code:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 #include #include using namespace std; int main() { string str; cout << "아래 한 줄을 입력하세요.(exit를 입력하면 종료합니다)"; while(true){ cout << endl << ">>"; getline(cin,str); if(str == "exit") break; for(int i = str.length()-1; i>=0; i--) cout << str[i]; } }

Explanation:

사용자로부터 입력받은 영문 한 줄을 거꾸로 출력하기 위해 string 클래스의 length() 멤버 함수를 이용해 끝에서부터 반대로 출력하였습니다.