saving in file

Hello all, I have written the following program which is running perfect but what I want is whenever I make any changes in my array I want it to be changed accordingly in my file.

my text file looks like this: 1 2 3 4 5

Any help is really appreciated.

#include <iostream>
#include <fstream>
using namespace std;
int change(int SEAT[5])
{
for (int i = 0; i <5; i++)
{
SEAT[i] = 1;
}
}
int main ()
{
ifstream input("test.txt");
int seat[5];
for (int i = 0; i <5; i++)
{
input >> seat[i];
}
for (int i = 0; i <5; i++)
{
cout << seat[i] << " ";
}
change(seat);
cout << "\nNew array is: \n";
for (int i = 0; i <5; i++)
{
cout << seat[i] << " ";
}
input.close();
return 0;
}
use ofstream output("filename"); to open a output file stream, use it like you are using cout stream, for example output << seat[0];
Yes I can do that but is there any way with which I can make changes in my original file.
Topic archived. No new replies allowed.