감 ¶
과 겼 process_wchar() 간 꼼 . ( 게 , ) . "" ver1과 그 "" 그 결과 고 "ㅏㅏㄱ" . 그 기 "" "ㅏㄱㅏ" 게 기 ver1 꾸 고, process_wchar() 기 게 .
ver1 ( ) ¶
~cpp #include <fstream> #include <algorithm> #include <string> using namespace std; string read_file(); void write_file(const string & str); void main() { string str = read_file(); reverse(str.begin(), str.end()); // 거꾸 STL write_file(str); } // . string read_file() { string str; fstream fin("source.txt"); char ch = fin.get(); while (ch != EOF) { str += ch; ch = fin.get(); } return str; } // . void write_file(const string & str) { fstream fout("result.txt"); fout << str; }
ver2 (까 ) ¶
~cpp #include <fstream> #include <algorithm> #include <string> using namespace std; string read_file(); void write_file(const string & str); void process_wchar(string & str); void main() { string str = read_file(); process_wchar(str); reverse(str.begin(), str.end()); // 거꾸 STL write_file(str); } // void process_wchar(string & str) { // str[i] char. 기게 . for (int i = 0; i < str.length(); i++) { if (str[i] < 0 && str[i + 1] < 0) { swap(str[i], str[i+1]); i++; } } } // . string read_file() { string str; fstream fin("source.txt"); char ch = fin.get(); while (ch != EOF) { str += ch; ch = fin.get(); } return str; } // . void write_file(const string & str) { fstream fout("result.txt"); fout << str; }