Printing to a line using ofstream
I am trying to output to a certain line in a file using ofstream. My file is automatically loaded with certain numbers, and I need to exchange one number at a time. For example, it originally outputs:
2400
0000
0000
0000
2500
0000
0000
0000
and I need to change it to:
2400
0000
0000
0000
2500
0000
1700
0000
I originally thought to use seekp, but I cannot seem to make it work correctly. Any ideas?
Re: Printing to a line using ofstream
Hi,
I'm trying to use a function to write information to a file.
Let's say I have a function called WriteStuff that will simply print the line number on each line.
Code:
void WriteStuff()
{
cout <<"Line 1" << endl;
cout <<"Line 2" << endl;
}
In main, I have a ofstream object called OutPutFile.
How can I use OutPutFile and store the information from the function in a file?
Code:
int main()
{
ofstream OutPutFile;
OutPutFile.open("StoreText.txt");
OutPutfile << WriteStuff();
// I dont know if this is correct
return 0;
}
Thanks
__________
Techstore are specialists in a range of Printing Services