简体   繁体   English

Fortran77将整数转换为String

[英]Fortran77 Casting integer to a String

Out of interest, I was trying to find a way to cast an integer to a String in Fortran77. 出于兴趣,我试图找到一种方法将一个整数转换为Fortran77中的String。 I came across CHAR(I) , but this converts the ASCII index I into the character in that postion. 我遇到了CHAR(I) ,但是这会将ASCII索引I转换为该位置中的字符。 Is there a way to just simply cast an integer to a String in Fortran77? 有没有办法简单地将一个整数转换为Fortran77中的String? How about vice versa? 反过来怎么样?

The Fortran way is to write the value of the integer into a string variable; Fortran的方法是将整数的值写入字符串变量; this operation is known as an internal write . 此操作称为内部写入 I'm heading out the door now so won't check this, and I have an ethical objection to writing FORTRAN77 or helping anyone else write it, so make no guarantee that the following doesn't contain bits of more modern Fortran. 我现在正在出门,所以不会检查这个,我有道德反对写FORTRAN77或帮助其他人写它,所以不能保证以下不包含更现代的Fortran。

First declare a character variable to receive the integer 首先声明一个字符变量来接收整数

character(len=12) :: int_as_string

then write the integer into it as you would normally write an integer to any other channel such as stdout 然后将整数写入其中,就像通常将整数写入任何其他通道(如stdout

write(int_as_string,'(i12.12)') my_int

I expect you'll want to set the format for writing the integer to something that suits you better 我希望你能设置将整数写入更适合你的东西的格式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM