Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Problem about output files

Problem about output files

Scheduled Pinned Locked Moved C / C++ / MFC
questionioshelp
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    knapak
    wrote on last edited by
    #1

    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.

    C PJ ArendsP 2 Replies Last reply
    0
    • K knapak

      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.

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      store all the numbers , then print them out when input stops ? Cleek | Image Toolkits | Thumbnail maker

      K 1 Reply Last reply
      0
      • C Chris Losinger

        store all the numbers , then print them out when input stops ? Cleek | Image Toolkits | Thumbnail maker

        K Offline
        K Offline
        knapak
        wrote on last edited by
        #3

        Yeah that works... I was wondering if there was a direct way to format the output in columns. Thanks!

        N 1 Reply Last reply
        0
        • K knapak

          Yeah that works... I was wondering if there was a direct way to format the output in columns. Thanks!

          N Offline
          N Offline
          Nish Nishant
          wrote on last edited by
          #4

          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

          K 1 Reply Last reply
          0
          • N Nish Nishant

            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

            K Offline
            K Offline
            knapak
            wrote on last edited by
            #5

            Can you explain? Portability? How do you use SetConsoleCursurPosition? I'm writing to a file not sending out to console. Thanks

            N 1 Reply Last reply
            0
            • K knapak

              Can you explain? Portability? How do you use SetConsoleCursurPosition? I'm writing to a file not sending out to console. Thanks

              N Offline
              N Offline
              Nish Nishant
              wrote on last edited by
              #6

              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 :-(

              1 Reply Last reply
              0
              • K knapak

                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.

                PJ ArendsP Offline
                PJ ArendsP Offline
                PJ Arends
                wrote on last edited by
                #7

                the endl that you are outputting after every number is what causes the newline to be output. Just control when you output an endl.


                "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!

                Within you lies the power for good; Use it!

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups