首页 > 解决方案 > 同时写入控制台和文件的简洁方法?

问题描述

我正在尝试简化控制台程序文本的输出。目前,这些程序以两种不同的方式运行:

  1. 直接来自 CMD 或批处理脚本
  2. 远程或盲目,由另一个程序调用

因此,所有输出给用户的信息都需要去控制台和一个默认的错误文件。

目前,我只是在重复自己:

write(*,*) "That wasn't a number!"
write(199,*) "That wasn't a number!"

我想出的最好的方法是使用子程序:

subroutine werr(string)

  implicit none

  character*(*), intent(in) :: string

  write(*,*) string
  write(199,*) string

  return

end subroutine

更好,但仍然需要call werr("Some text or another.")

有没有办法模仿写作的方式,我可以简单地拥有werr("Some text or another.")

标签: fortranwindows-console

解决方案


推荐阅读