// 22_22-10.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#include "stdafx.h"
#include <iostream>
#include <windows.h>
#include <fstream>
#include <cstring>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	ifstream fin;
	ofstream fout;
	char ss[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	int i;

	fout.open("tmpfile.txt", ios_base::out | ios_base::binary);
	if (!fout) {
		cout << "出力ファイルをオープンできませんできません\n";
		MessageBox(NULL, _T("Check Console Window"), L"MessageBox", MB_OK);
		return 1;
	}
	fout.write(ss, strlen(ss));
	fout.write("1234567890", 10);
	fout.close();

	fin.open("tmpfile.txt", ios_base::in | ios_base::binary);
	if (!fin) {
		cout << "入力ファイルをオープンできません\n";
		MessageBox(NULL, _T("Check Console Window"), L"MessageBox", MB_OK);
		return 1;
	}

	do {
		fin.read(ss, 10);
		for (i = 0; i < fin.gcount(); i++) {
			cout << ss[i];
		}
		cout << " gcount=" << fin.gcount() << '\n';
	} while (fin.gcount() == 10);

	fin.close();

	MessageBox(NULL, _T("Check Console Window"), L"MessageBox", MB_OK);

	return 0;
}

