As long the result is the same length as the original (or shorter, and you don't mind adding spaces to cover the difference) it's pretty easy: seek to where you want to do the modification, write the new data, and you're done:
#include <fstream>
#include <ios>
int main() {
std::fstream file("yourfile.txt", std::ios::in | std::ios::out);
file.seekp(7);
file << "19";
return 0;
}
If the data you want to write won't "fit" in between other things you want to preserve, you need to re-write the remainder of the file, typically copying from the old file to a new one, modifying the data as required along the way through.
Edit: something like this:
#include <fstream>
#include <ios>
#include <iterator>
#include <vector>
int main() {
std::vector<double> data;
std::fstream file("yourfile.txt", std::ios::in | std::ios::out);
std::copy(std::istream_iterator<double>(file),
std::istream_iterator<double>(),
std::back_inserter(data));
file.clear();
file.seekp(0);
data[2] = 19.98;
std::copy(data.begin(), data.end(), std::ostream_iterator<double>(file, " "));
return 0;
}
This has a few effects that you may not want -- particularly, as it stands, it destroys whatever "line" oriented structure the original may have had, and simply writes out the result as one long line. If you want to avoid that, you can (for example) read in a line at a time, convert the numbers in the line (e.g. put then into a stringstream, then read them out of there as doubles), modify those, put the result back into a string, and write out the line with a "\n" at the end.