[Solved] Take input from keyboard and edit existing text file


You need to write to your file using the file stream you have defined once you have taken your inputs and you can do that using fout as follows. Additionally, there are different modes in which you could open a file for writing to it, which you can go through here.

    fout.open("FootballTeam.txt");

    cout << "Enter first name ";
    cin >> forename;
    fout << forename << " ";
    cout << endl;
    cout << "Enter surname ";
    cin >> surname;
    fout << surname << " ";
    cout << endl;
    cout << "Enter strike power  ";
    cin >> strike;
    fout << strike << " ";
    cout << "Enter defence power  ";
    cin >> defence;
    fout << defence << " ";
    cout << "Enter midfield power  ";
    cin >> midfield;
    fout << midfield << "\n";

Open and take a look at FootballTeam.txt to find what the above snippet does.

Hope that helps.

solved Take input from keyboard and edit existing text file