Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  sdf
Language: C/C++
Code:
#include "pch.h"
#include <fstream>
#include <iostream>
#include <string>

using namespace std;

class OnlyText{
public:
     OnlyText() {
          deTexter();
     }

     void deTexter() {
          //파일열기
          getFile();

          //사용자가 그냥 종료할 경우
          if (!input.is_open()) return;

          //파일처리
          //쓰기위한 파일 열기
          output.open("new-" + inputFileName);

          //한줄 읽기 반복
          while (input.getline(buffer, sizeof(buffer))) {
               for (int i = 0; buffer[i] != NULL; i++) {
                    //숫자 + ':' 까지 삭제
                    if (47 < (int)buffer[i] && (int)buffer[i] < 59) {
                         buffer[i] = NULL;
                         continue;
                    }
                    //    , -   삭제
                    if (buffer[i] == ',' || buffer[i] == '-') {
                         buffer[i] = NULL;
                         continue;
                    }
                    // < > 안에있는 내용은 모두 삭제
                    if (buffer[i] == '<') {
                         buffer[i] = NULL;

                         while (buffer[++i] != '>') {
                              buffer[i] = NULL;
                         }
                         buffer[i] = NULL;
                    }
               }
               output << buffer << endl;
          }

          //파일 닫기
          closeFile();
     }

     void closeFile() {
          if (input.is_open()) input.close();
          if (output.is_open()) output.close();
     }

     void getFile() {
          cout << "파일 이름.확장자 입력: ";
          getline(cin, inputFileName);

          input.open(inputFileName);

          //열리면 실행, 안열리면 재입력 혹은 종료
          if (!input.is_open()) {
               cout << inputFileName + "을 찾을 수 없습니다. 재입력 하시겠습니까? (Y/N): ";

               //실패한 string 재활용
               getline(cin, inputFileName);

               if (inputFileName == "Y" || inputFileName == "y") {
                    system("cls");
                    getFile();
               }
               return;
          }
     }
private:
     ifstream input;
     string s;
     string inputFileName;
     char buffer[150];
     ofstream output;
};
int main()
{
     OnlyText ot;
     cout << "완료되었습니다!" << endl;
}
Comments: