U E D R , A S I H C RSS

문자반대출력/문보창

글과 같 가 담겼다면 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;
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:29:29
Processing time 0.0153 sec