감 ¶
만 글과 같 문가 담겼다면 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;
}










