I am looking for some advice.
My situation:
-
Application works with text local file.
-
In file are somewhere tags like this:
correct = "TEXT"
. Unfortunatelly, there can be unlimited spaces between correct, = and “TEXT”.
-
Obtained text is testing in function and may be replaced (the change must be stored in the file).
correct = "CORRECT_TEXT"
My current theoretical approach:
-
With ofstream — read by line to string.
-
Find tag and make change in string.
-
Save strings as lines to the file.
Is there some simplify way (with iterators?) in C++ with using standard system libraries only (unix).
Thank you for your ideas.
Here is a possible solution that uses:
std::getline()std::copy()istream_iteratorostream_iteratorvectorExample:
I am not sure exactly what the manipulation of the lines should be but you could use:
std::string::find()andstd::string::substr()boost::split()EDIT:
To avoid storing every line in memory at once the initial
copy()can changed to write to an alternative file, followed by a filerename():