Development
[STL/string] 문자열 뒤집기
알 수 없는 사용자
2008. 11. 26. 21:38
#include <iostream.h>
#include <stdlib.h>
#include <string>
#include <algorithm> //reverse()
int main()
{
char buf[100] = "I am a Boy!";
string str = buf;
cout << buf << endl;
cout << str << endl;
cout << "-----reverse-----" << endl;
// 문자열 뒤집기
reverse( str.begin(), str.end() );
strcpy(buf, str.c_str() );
cout << buf << endl;
cout << str << endl;
// 뒤집어서 출력하기.
copy( str.rbegin(), str.rend(), ostream_iterator<char>(cout) );
cout << endl;
cin.get();
return 0;
}
#include <stdlib.h>
#include <string>
#include <algorithm> //reverse()
int main()
{
char buf[100] = "I am a Boy!";
string str = buf;
cout << buf << endl;
cout << str << endl;
cout << "-----reverse-----" << endl;
// 문자열 뒤집기
reverse( str.begin(), str.end() );
strcpy(buf, str.c_str() );
cout << buf << endl;
cout << str << endl;
// 뒤집어서 출력하기.
copy( str.rbegin(), str.rend(), ostream_iterator<char>(cout) );
cout << endl;
cin.get();
return 0;
}