//Template Method Pattern

#include <iostream>

#include <string>

#include <conio.h>

using namespace std;

 

class LineEidt {

        string text;

public:

        virtual bool validate(char ch) { return true; }

 

        string getText() {

               text.clear();

               while(true) {

                       char ch=_getch();      //표준 입력 스트림으로부터 문자 하나를 읽어온다.

                       if(ch==13)     break;

                      

                       if(validate(ch)) {

                              text.push_back(ch);

                              cout << ch;

                       }

               }

               cout << endl;

               return text;

        }

};

 

class NumberLineEdit : public LineEidt {

        bool validate(char ch) { return isdigit(ch)? true : false; }

};

 

 

int main() {

        NumberLineEdit edit;

       

        while(true) {

               string s = edit.getText();

               cout << s << endl;

        }

 

        return 0;

}

Posted by No names
,