I need a function to work with the entire C++ file.



  • I wrote a function to encrypt the text with a banal shift, which is the text from the file. encrypted and recorded back in the file, which she's handling, but now she can only work with the first line. What do you say or change what would work with the other lines? Function itself:

    ifstream file;
        file.open(name_file);
    
    char str1[255];
    string str;
    
    while (getline(file, str)) {
        strcpy_s(str1, str.c_str());
    
        for (int i = 0; i < strlen(str1); i++)
        {
           str1[i] += 5;
        }
        cout << str1 << endl;
    }
    file.close();
    



  • ifstream serves to read the file to record the data in the file, it is necessary to use the stream. About this is the reading of the data from the file and the recording into another file:

    ifstream input(inputName);
    ofstream output(outputName);
    if (!input.is_open()) return -1; // Проверка открытия
    string str;
    while (true) { // Цикл для перебора всех строк
        // Code
        input >> str; // Считали строку из файла
        if(str.size()==0 && input.eof()) break; // Проверка, что файл кончился
        output << str; // Записали строку в файл
    }
    input.close();
    output.close();
    

    I recommend that we read the information from this. http://cppstudio.com/post/446/ I think you'll find everything you're interested in.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2