CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM (https://www.cfd-online.com/Forums/openfoam/)
-   -   OFstream backspace (https://www.cfd-online.com/Forums/openfoam/86733-ofstream-backspace.html)

dandalf March 31, 2011 11:21

OFstream backspace
 
Hi all,

I'm writing a function to be called in the controlDict, the output is a .dat file that I then want to use on each iteration as a timeDataFile.

On each iteration I want to either erase the last character in the file, and the write the desired data, or rewind the pointer by one place.

I have tried to use a backspace character "\b" however it did not backspace the file. instead input an unrecognizable character.

I also tried
Code:

outfile.seekp (pos-1);
But that resulted in the error
Code:

error: ‘class Foam::OFstream’ has no member named ‘seekp’
Is there a simple solution?

mturcios777 March 31, 2011 17:45

OFStream is a derived class that simplifies a lot of the IO for FOAM usage, but it also limits that you can only get around by using the actual fstream classes provided by the c++ libraries, or possibly casting the OFStream as something else.

Out of curiosity, why is only the last character being replaced?

dandalf April 1, 2011 04:43

Thanks murcios777

I'm wrighting a timeDataFile on the fly,

basically a list of parameters, each iteration it calculates the parameters for the next time iteration. However the entire list needs to be surrounded by parenthesis, so each time I add a line I need to remove the close brackets, write the line, then add another close brackets.

There is probably a much easier way of doing this, any suggestions would be appreciated.

mturcios777 April 5, 2011 12:24

Do you need to keep all the iterations of the parameters, or do you just need the one from the last iteration. If its the latter, then it seems you could look at the code that allows the controlDict to be modified at runTime.

In fact, making this list of parameters a dictionary might be the best option, and make it run time modifiable. Then you can just have it living in your system folder, and the existing foam utilities handle all the writing/rewriting. The class structure for a dictionary is located here


All times are GMT -4. The time now is 22:44.