1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Juliaで学ぶプログラミング入門 IO

1
Last updated at Posted at 2022-12-04

IO(入出力 input/output)

juliaでの入出力(IO)には、標準的な入出力関数が用意されています。例えば、標準入力から文字列を取り出すには、次のようにします。

# 標準入力から文字列を取り出す
line = readline()
println(line)

このプログラムを実行すると、次のようになります。

# 入力
Hello, World!

# 出力
Hello, World!

上記にもありますが文字列を標準出力に出力するには、次のようにします。

# 文字列を標準出力に出力する
line = "Hello, World!"
println(line)

このプログラムを実行すると、次のようになります。

# 出力
Hello, World!

また、juliaでは、外部ファイルへの読み書きもできます。例えば、次のようにして、テキストファイルに書き込むことができます。

# ファイルへの書き込み
open("hello.txt", "w") do file
  write(file, "Hello, World!")
end

また、次のようにして、テキストファイルから読み込むことができます。

# ファイルからの読み込み
open("hello.txt", "r") do file
  line = readline(file)
  println(line)
end

これらのプログラムを実行すると、hello.txtというテキストファイルが作成され、その中に「Hello, World!」という文字列が書き込まれます。また、そのファイルを読み込むことで、その文字列が標準出力に表示されます。

これらの標準的な入出力関数を使えば、juliaで簡単に入出力を行うことができます。

参考図書

1から始めるプログラミング

Juliaプログラミングクックブック

天才プログラマー タンメイが教える Julia超入門

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?