// 26_26-12.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';
	}
	Str80 operator()(int pos, int n);
};

Str80 Str80::operator()(int pos,int n)
{
	Str80 s80 = "";
	char *p1 = s80.text, *p2 = text + pos;
	if (pos<0 || len(text)<pos) {
		n = -1;
	}
	for (int i = 0; i < n && *p2; i++) {
		*p1++ = *p2++;
	}
	*p1 = '\0';
	return s80;
}

int _tmain(int argc, _TCHAR* argv[])
{
	Str80 s1("ABCDEFGH"), s2;
	s2 = s1(2, 4);
	s1.disp();
	s2.disp();

	MessageBox(NULL, _T("Check Console Window"), L"MessageBox", MB_OK);

	return 0;
}

