// 22_22-11.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#include "stdafx.h"
#include <iostream>
#include <windows.h>
#include <fstream>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	ifstream fin;
	ofstream fout;
	char ch;

	fout.open("smp.txt");
	if (!fout) {
		return 1;
	}
	fout << "ABCDEFGHIJKLMNOPQRST\n";
	fout.close();

	fin.open("smp.txt");
	if (!fin) {
		return 1;
	}

	cout << "-----2文字読み込む\n";
	fin.get(ch);
	cout << "ch=" << ch << '\n';
	fin.get(ch);
	cout << "ch=" << ch << '\n';

	cout << "-----put_backし1文字読み込む\n";
	fin.putback(ch);
	//fin.unget();
	fin.get(ch);
	cout << "ch=" << ch << '\n';

	cout << "-----2文字読み込む\n";
	fin.get(ch);
	cout << "ch=" << ch << '\n';
	fin.get(ch);
	cout << "ch=" << ch << '\n';

	cout << "-----peekした文字を表示する\n";
	ch = (char)fin.peek();
	cout << "peek文字=" << ch << '\n';

	cout << "-----peek後に2文字読み込む\n";
	fin.get(ch);
	cout << "ch=" << ch << '\n';
	fin.get(ch);
	cout << "ch=" << ch << '\n';

	fin.close();

	MessageBox(NULL, _T("Check Console Window"), L"MessageBox", MB_OK);

	return 0;
}

