mardi 23 août 2022

How to delete specific line from text file c++

This is my text file content.

1
2
3

I want to delete line of this file.

#include <iostream>
#include <fstream>
#include <string>
std::fstream file("havai.txt", ios::app | ios::in | ios::out);

int main()
{
    std::string line;
    int number;
    std::cout << "Enter the number: ";
    std::cin >> number;
    while (file.good())
    {
        getline(file, line);
        if (std::to_string(number) == line)
        {
            // how to delete that line of my text file
        }
    }
    return 0;
}

how to delete that line in if statement?

Aucun commentaire:

Enregistrer un commentaire