1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

C++のHello World、23年越しの進化

Last updated at Posted at 2025-08-23

C++は「とっつきにくい言語」と言われがちだ。
その一因は、言語初心者が最初に書く「Hello World」プログラムにあるのではないだろうか。

#include <iostream>

int main() {
    std::cout << "Hello World\n";
    return 0;
}
  • こんな簡単な出力なのに冗長
  • 直感的じゃない
  • std::coutってそもそも何? 関数なの?

解決策

C++23からは、新しく std::print(改行なし)std::println(改行あり) が導入され、より直感的に「Hello World」を書けるようになった。

#include <print>

int main()
{
  std::println("Hello {}!", "world");
  std::println(stdout, "Hello world!"); // 標準出力に出力
}

出力

Hello world!
Hello world!

これでもう、言語学習のはじめからずっこけることはなくなるね(たぶん)。

おわり

C++入門サイトには、従来の方法に加えて新しい書き方も紹介してほしい。
C++がprint関数を手に入れるまで23年かかりました…。Cには最初からあったのに。

1
2
5

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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?