如何在Fortran中不使用换行符进行编写? [英] How to write without a newline in Fortran?
本文介绍了如何在Fortran中不使用换行符进行编写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写一段代码,我计划编写一个10x10001矩阵的 .txt
文件:
do i = 1,10
read(1,10)seed!从文件1读取数字
写入(2,20)种子!在文件2中的数字
do k = 1,10000
seed = mod((a * seed),m)
R = seed / m
write(2,20) R!我希望所有这些数字都在种子旁边,而不是换行。
end do
end do
但是所有的 R
都是用新行写的。
有没有办法用空格而不是新行来区分每个数字,还是应该使用C ++和管道实现相同的代码?
解决方案
可以使 write
不在最后添加换行符,代码如下:
write(2,20,advance =no)R
I'm writing a piece of code by which I plan to write a .txt
file that's a 10x10001 matrix:
do i = 1, 10
read(1,10) seed !Read a number from file 1
write(2,20) seed !Write that number in file 2
do k = 1, 10000
seed = mod((a*seed),m)
R = seed/m
write(2,20) R !I want all these numbers to be next to the seed, not on new lines
end do
end do
But all the R
's are written on new lines.
Is there a way to separate every number with a space instead of a new line, or should I implement this same code using C++ and pipelines?
解决方案
You can make write
not add a newline at the end with the following code:
write(2, 20, advance="no") R
这篇关于如何在Fortran中不使用换行符进行编写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文