0
0

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++23をVSCodeで動かす (WSL/Ubuntu, g++13/g++14)

0
Last updated at Posted at 2026-04-16

新しいC++ではstd::printという関数があるらしく、使ってみようと思ったが、
VSCodeでのやり方に少し手間取ったので備忘録として書く。

std::printについて:std::printについて @exli3141

C++23について:【C言語・C++】C23とC++23の概要@techsuwako

環境

  • Windows 11 Pro
  • Ubuntu 24.04.4 LTS (WSL2)
  • g++14; GCC 13+?(g++13/g++14)
  • VSCode version: 1.116.0

エラー内容

エディタ上で以下エラー

image.png

namespace "std" has no member "print"

実行時には以下エラー

error: ‘print’ is not a member of ‘std’
    3 | int main() { std::print("Hello world!"); }
      |                   ^~~~~

解決方法

そもそもg++で動くかどうか確認する

g++ -std=c++23 main.cpp -o main
./main

動かなかったら、g++を更新 [GCC 13+?(g++13/g++14) など?]

エディタ上のエラーの対処|C++ standardの変更

image.png
ここから飛べる→ vscode://settings/C_Cpp.default.cppStandard

実行時のエラーの対処|C++コンパイラの導入

Linuxに新しめなC++コンパイラが入っていなければ、たとえばg++-14をインストールする。

  1. Command Palette(Ctrl+Shift+P)
  2. C/C++: Select IntelliSense Configurationを選択
  3. Use g++-14を選択 (g++-13以上なら良いかも)

これで、エディタ上のエラーは消えるはず。

Run and Debugのエラーの対処|task.jsonへC++ standardの設定

task.jsonはC++ standard設定が反映されないので、"-std=c++23"を付け足す。
image.png

実行確認

#include <print>

int main() { std::print("Hello world!"); }
Hello world!

OK.

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?