How do I format a PRINT or WRITE statement to overwrite the current line on the console screen?

后端 未结 4 738
借酒劲吻你
借酒劲吻你 2021-01-05 05:04

I want to display the progress of a calculation done with a DO-loop, on the console screen. I can print out the progress variable to the terminal like this:

         


        
4条回答
  •  独厮守ぢ
    2021-01-05 05:40

    There is no solution to this question within the scope of the Fortran standards. However, if your compiler understand backslash in Fortran strings (GNU Fortran does if you use the option -fbackslash), you can write

      write (*,"(A)",advance="no") "foo"
      call sleep(1)
      write (*,"(A)",advance="no") "\b\b\bbar"
      call sleep(1)
      write (*,"(A)",advance="no") "\b\b\bgee"
      call sleep(1)
      write (*,*)
      end
    

    This uses the backslash character (\b) to erase previously written characters on that line.

    NB: if your compiler does not understand advance="no", you can use related non-standard tricks, such as using the $ specifier in the format string.

提交回复
热议问题