// 26_26-11.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#include "stdafx.h"
#include <iostream>
#include <windows.h>
#include <cstdlib>

using namespace std;

class Str80 {
private:
	char text[81];
	int len(char *s) {
		int n = 0;
		while (*s++) {
			++n;
		}
		return n;
	}
	void cpy80(char *s) {
		int n;
		for (n = 0; n < 80 && *s; n++) {
			text[n] = *s++;
		}
		text[n] = '\0';
	}
public:
	Str80(char *ss = "") {
		cpy80(ss);
	}
	void disp() {
		cout << "text=" << text << '\n';
	}
	char &operator[](int n);
};

char &Str80::operator [](int n)
{
	if (n<0 || n>=len(text)) {
		cout << "添字が範囲外\n";
		exit(1);
	}
	return text[n];
}

int _tmain(int argc, _TCHAR* argv[])
{
	Str80 ss("ABCD");
	char ch;

	ss.disp();
	ch = ss[2];
	cout << ch << '\n';
	ss[2] = 'x';
	ss.disp();

	MessageBox(NULL, _T("Check Console Window"), L"MessageBox", MB_OK);

	return 0;
}

