I am wondering how to go through a text file and locate a given word (“foobar”) at different locations within each line but then realign the word to the same position in a new text file, let me know if this doesn’t make sense.
***in text file***
1 foobar baz
2 foobar baz
3 foobar baz
****out text file***
1 foobar baz
2 foobar baz
3 foobar baz
The io manipulator std::setw() from can be used to create fixed-length columns in text output, and std::setfill() is used to specify the fill character:
Will print:
This can easily be used to create a small program which reads all lines from one file and writes them to another file and at the same time aligns all columns (in the below program >> is used to read one column, which means that the columns in the in file are supposed space-separated, by one or more whitespace characters):
I didn’t compile the program but it should work :).