Q&A
VScodeを用いてC++の環境構築をしています。
windowsからMacに乗り換えたので一から環境構築を再び始めたが、どうもうまくプログラムが実行できません。
C++
1#include <bits/stdc++.h> 2using namespace std; 3#define rep(i,a,b) for(int i=a;i<b;i++) 4#define rrep(i,a,b) for(int i=a;i>=b;i--) 5#define fore(i,a) for(auto &i:a) 6#define all(x) (x).begin(),(x).end() 7typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; 8template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } 9template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } 10using P = pair<int,int>; 11using Graph = vector<vector<int>>; 12 13int main() { 14 int n,m,x,t,d; 15 cin >> n >> m >> x >> t >> d; 16 17 if( m >= x ) cout << t << endl; 18 19 else{ 20 cout << t - d*(x - m) << endl; 21 } 22 23 return 0; 24}
のコードにおいて
using Graph = vector<vector<int>>;
に、a space is required between consecutive right angle bracketsとエラーメッセージが出る。
また、"pair"と"vector"に対し、alias declarations are a c++11 extensionの警告も出る。
現状
ビルドとデバックがうまく処理されない。
code runnerを用いようとしたが、違うフォルダ内の実行ファイルにうまく利用できない。
✔️<bits/stdc++.h>のパスは通っている状態。
✔️gcc, homebrew, code runner,CodeLLDB インストール済み。
.jsonのファイルと実行ファイルは同じディレクトリ、異なるフォルダ内にある。
実現したいこと
エラーを解決しatcoderで解いたプログラムを実行とデバッグ、数値を代入したら計算結果がきちんと出力される。
setting.json
C++
1{"clang.executable": "clang++", 2 "code-runner.runInTerminal": true, 3 "clang.cxxflags": [ "-std=c++14" ], 4 "code-runner.executorMap": { 5 "javascript": "node", 6 "java": "cd $dir && javac $fileName && java $fileNameWithoutExt", 7 "c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt", 8 "cpp": "cd $dir && g++ -O2 -std=c++14 $fileName && ./a.out" 9 }, 10 "[cpp]": { 11 "editor.defaultFormatter": "ms-vscode.cpptools" 12 } 13}
⚠️なぜだかこのコードの1行目と3行目の
"clang.executable": "clang++",
"clang.cxxflags": ["-std=c++14"],
が他より薄く表示されている。
c_cpp_properties.json
C++
1{ 2 "configurations": [ 3 { 4 "name": "Mac", 5 "includePath": [ 6 "${workspaceFolder}/**", 7 "/usr/local/include/bits/*" 8 ], 9 "defines": [], 10 "macFrameworkPath": [ 11 "/Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk/System/Library/Frameworks" 12 ], 13 "compilerPath": "/opt/homebrew/bin/g++-11", 14 "cStandard": "c17", 15 "cppStandard": "c++17", 16 "intelliSenseMode": "macos-clang-arm64" 17 } 18 ], 19 "version": 4 20}
launch.json
C++
1{ 2 "version": "0.2.0", 3 "configurations": [ 4 { 5 "name": "(lldb) Launch", 6 "type": "lldb", 7 "request": "launch", 8 "program": "${workspaceFolder}/a.out", 9 "args": [], 10 "cwd": "${workspaceFolder}", 11 "preLaunchTask": "Build with gcc" 12 } 13 ] 14}
tasks.jsonのコード
C++
1{ 2 "version": "2.0.0", 3 "tasks": [ 4 { 5 "label": "Build with gcc", 6 "type": "shell", 7 "command": "g++", 8 "args": [ 9 "-std=c++17", 10 "-gdwarf-3", 11 "atcoder.cpp", 12 "-o", 13 "a.out", 14 "--debug" 15 ], 16 "group": "build" 17 }, 18 { 19 "type": "cppbuild", 20 "label": "C/C++: clang++ アクティブなファイルのビルド", 21 "command": "/usr/bin/clang++", 22 "args": [ 23 "-fdiagnostics-color=always", 24 "-g", 25 "${file}", 26 "-o", 27 "${fileDirname}/${fileBasenameNoExtension}" 28 ], 29 "options": { 30 "cwd": "${fileDirname}" 31 }, 32 "problemMatcher": [ 33 "$gcc" 34 ], 35 "group": { 36 "kind": "build", 37 "isDefault": true 38 }, 39 "detail": "デバッガーによって生成されたタスク。" 40 } 41 ] 42}
[主に参考にした文献]
https://qiita.com/dhirabayashi/items/fc4327b1771d07502adc-
https://qiita.com/EngTks/items/ffa2a7b4d264e7a052c6
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。