So my problem is that I can't seem to figure out how to 'set tellp()' to the beginning of a particular line and then replace it with a new one. I've also just realised that I'm going to have to also figure out how to avoid writing over any of the next line too.. I should probably be able to figure that out though. This is what I've tried so far
std::fstream indiLine;
indiLine.open ("indiTest.mdl",std::ios::in | std::ios::out); if (indiLine.is_open())
{
std::string inOut;
int line_num = 0;
while (getline(indiLine,inOut))
{
if (line_num-1 == vNum) { std::cout << inOut << std::endl ;
break; }
line_num++;
}
indiLine.seekp(indiLine.tellg());
indiLine << "R";
indiLine.close();
}
else{ debugOut("Save Failure On Open",500); }
and the output for the particular lines I've tested:
Quote:
before subroutine;
X200Y200Z200E8D5
X-200Y200Z200E1D5
after subroutine;
X200Y200Z20RE8D5
X-200Y200ZR00E1D5
and those are the 8th and 9th lines when 'vNum' is at 5 and then 6 so they should be the 6th and 7th lines. Or rather those are the ones I'm after, in these particular instances.
so tellg() is giving me the wrong position.. If it was at the end of the line I could have just done something like
indiLine.seekp(indiLine.tellg-inOut.length());
but it's not so I don't really know what to do. Also it seems likely to me that I won't be able to just deduct an 'int' from the type that 'tellg()' returns.
Any hints on what to do to solve it this way would be really great and if I'm going at it from the completely wrong angle let me know what you have in mind, even better. Thanks guys, you're all awesome. :)