Problem about output files
-
Hi all I have a code that runs a simulation producing numeric outputs of a time series multiple times. I don't know in advance how long is the series or how many times the simulation will run (defined by user at run time). I would like to have the program to write the results out to a file in one column per simulation run instead of a single column where the result of each simulation is separated by some marker. The code to write the output in one column would be something like this:
ofstream WriteOutput(OutputData.out,ios::app) for(sim=1; sim<=nsims; sim++) { for(t=1; t<=n; t++) { y=f(x[t]); WriteOutput >> y >> endl; if(t==n) WriteOutput >> "#" >> endl; } }
This produces an output like this: 3 4 5 6 # 4 5 6 7 # Instead, I'd like a code to write an output such as: 3 4 4 5 5 6 6 7 How can I do this? Thanks! C. -
Hi all I have a code that runs a simulation producing numeric outputs of a time series multiple times. I don't know in advance how long is the series or how many times the simulation will run (defined by user at run time). I would like to have the program to write the results out to a file in one column per simulation run instead of a single column where the result of each simulation is separated by some marker. The code to write the output in one column would be something like this:
ofstream WriteOutput(OutputData.out,ios::app) for(sim=1; sim<=nsims; sim++) { for(t=1; t<=n; t++) { y=f(x[t]); WriteOutput >> y >> endl; if(t==n) WriteOutput >> "#" >> endl; } }
This produces an output like this: 3 4 5 6 # 4 5 6 7 # Instead, I'd like a code to write an output such as: 3 4 4 5 5 6 6 7 How can I do this? Thanks! C.store all the numbers , then print them out when input stops ? Cleek | Image Toolkits | Thumbnail maker
-
store all the numbers , then print them out when input stops ? Cleek | Image Toolkits | Thumbnail maker
-
Yeah that works... I was wondering if there was a direct way to format the output in columns. Thanks!
knapak wrote:
Yeah that works... I was wondering if there was a direct way to format the output in columns.
If you are not worried about portability issues, you can use
SetConsoleCursorPosition
-- modified at 17:16 Thursday 15th December, 2005 -
knapak wrote:
Yeah that works... I was wondering if there was a direct way to format the output in columns.
If you are not worried about portability issues, you can use
SetConsoleCursorPosition
-- modified at 17:16 Thursday 15th December, 2005 -
Can you explain? Portability? How do you use SetConsoleCursurPosition? I'm writing to a file not sending out to console. Thanks
knapak wrote:
Can you explain? Portability? How do you use SetConsoleCursurPosition? I'm writing to a file not sending out to console.
Oops, ignore my post then :-(
-
Hi all I have a code that runs a simulation producing numeric outputs of a time series multiple times. I don't know in advance how long is the series or how many times the simulation will run (defined by user at run time). I would like to have the program to write the results out to a file in one column per simulation run instead of a single column where the result of each simulation is separated by some marker. The code to write the output in one column would be something like this:
ofstream WriteOutput(OutputData.out,ios::app) for(sim=1; sim<=nsims; sim++) { for(t=1; t<=n; t++) { y=f(x[t]); WriteOutput >> y >> endl; if(t==n) WriteOutput >> "#" >> endl; } }
This produces an output like this: 3 4 5 6 # 4 5 6 7 # Instead, I'd like a code to write an output such as: 3 4 4 5 5 6 6 7 How can I do this? Thanks! C.the
endl
that you are outputting after every number is what causes the newline to be output. Just control when you output anendl
.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04 "There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05 Within you lies the power for good - Use it!