Using C++, I want to generate a file in which I have to add the line number to the end of each line. Some lines end after 13th character, some of them end after 32nd. But the line numbers should be in the end. A line is 80 characters long, the last number of the line should be in the 80th column of the line.
Is there a way to accomplish this? I initialize my file using ofstream, use C++.
Well, here’s one way to go about it using a stringstream:
Basically sets the stream to right align and pad to 80 chars, lays down your line number, and then seeks to the beginning of the line where you can output whatever you want. If you keep writing a long line of data into the stream you’ll overwrite your line number, of course.