программа для преобразования файлов c ++ - PullRequest
0 голосов
/ 28 апреля 2020

У меня проблемы с запуском этой программы на C ++. Цель этого состоит в том, чтобы открыть входной файл (есть 2 file1.txt и file2.txt), которые находятся в разделителе канала. Когда пользователь вводит имя файла any, он должен преобразовываться в запятую в выходном CSV-файле, а затем закрывать все файлы, когда это необходимо. Общая проблема, с которой я сталкиваюсь, заключается в преобразовании файлов и в том, что он дает мне ошибки из-за наличия нескольких букв в регистре.

Это файл file1.txt, который был задан в виде разделителя каналов:

Миль в час | 6,445 | «вторая» команда | 5,54 | 9,98 | 6,555.00 «Завершающая» игра | осталось в «начале» | | Элизабет, Нью-Джерси | 25,25 | 6,78 | 987,01 | Конец ночью или днем ​​| «Давайте go» | 65 978,21 | 0,00 | 123,45 Ночь левостороннего базирования | 10.07.1900 ||| 4,07 | 777,23 «Давайте начнем» | Начать бейсбольный матч | Запуск новой игры, чтобы выиграть

#include <iostream>
#include <iomanip>
#include <fstream>

 using namespace std;

  ifstream inFile1 ,inFile2, outFile1, outFile2;
  string inFile, outFile;

int main() {

char choice;
char str

switch(choice) {

case 'oi':// open input files
case 'OI': {  std::cout << "Enter the input filename 1:";
    std::cin >> inFile;
    inFile1.open(inFile.c_str());
    if(inFile1.is_open())
      std::cout<<"File 1 Opened"<<std::endl;

      inFile.clear();

       std::cout << "Enter the input filename 2:";
       std::cin >> inFile;

       inFile2.open(inFile.c_str());
       if(inFile2.is_open())
       std::cout<<"File 2 Opened"<<std::endl;
                }
 case 'ci': // close input files.
 case 'Ci': {

    std::cin>>str;

    if(toupper(str[0])=='C')
      {
     if(toupper(str[1])!='F')
         str[0]='\0';

      inFile1.close();
      inFile2.close();
            }
}
case 'oo': // open output files.
case 'OO': { 
std::ofstream outFile1,outFile2;
    std::string outFile;
    std::cout << "Enter the output filename 1:";
    std::cin >> outFile;
    outFile1.open(outFile.c_str());
    if(outFile1.is_open())
   std::cout<<"File 1 Opened"<<std::endl;
   outFile.clear();

    outFile2.open(outFile.c_str());
    if(outFile2.is_open())
    std::cout<<"File 2 Opened"<<std::endl;

}
 case 'co': // close output files.
 case 'CO': {
 outFile1.close();
 outFile2.close();
}
case 'f': // file conversion
case 'F': {

// read line by line into array and the convert to comma delimited  

 string myArray[5];

    for(int i = 0; i < 5; ++i)
    {
        file >> myArray[i];
{ string temp;
    while (getline (inputFile, temp, '|')) {
        if (temp.find(",") != string::npos)
            cout << '"' << temp << "\",";
        else
            cout << temp << ',';
}

}
   }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...