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?

[tips][vscode] cpp version setting

Last updated at Posted at 2024-10-12

Vscodeのcpp version

std::set<char> s = {'a', 'b', 'c'};

// キー2の要素が含まれているか
if (s.contains('b')) {
  std::cout << "contain" << std::endl;
} else {
  std::cout << "doesn't contain" << std::endl;
}

contains関数はcpp+20から導入された関数です。vscodeの設定がc++20以上出ないと次のようなエラーを出力します。
スクリーンショット 2024-10-12 14.24.35.png

同じこと言ってる人いた。
https://stackoverflow.com/questions/69456226/class-stdmap-has-no-member-contains-in-visual-studio-code

ただし、code runnnerに次のコマンドを指定してる場合は、-std=c++20としてコンパイラがコンパイルするので実行されます(当たり前か)

g++ -std=c++20 hoge.cpp -o hoge
#include <iostream>

int main() {
  std::cout << __cplusplus << std::endl;
  return 0;
}

Vscodeでcppのversionを設定する方法

設定もしくはSettingを開く。
スクリーンショット 2024-10-12 14.19.14.png

cppStandardを検索。

スクリーンショット 2024-10-12 14.19.03.png

pulldownから、ユーザー、ワークスペース両方の設定をc++20に選択。

これでコンパイルエラーが綺麗に消えます。めでたし。

intelliSenseMode

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?