Unable to run C++ files using code runner on VS Code

Viewed 2838

I am unable to run my CPP files on VS Code through code runner extension. It happened after I tried to activate conda as python interpretator on vs code.

Here is the error it shows after running a C++ file(It shows the same error on running other cpp files as well)

PS C:\Users\hp> g++ *.cpp -o job_queue && ./job_queue.exe
At line:1 char:24
+ g++ *.cpp -o job_queue && ./job_queue.exe + ~~
The token '&&' is not a valid statement separator in this version.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : InvalidEndOfLine

settings.json

{
"C_Cpp.updateChannel": "Insiders",
"python.pythonPath": "C:\\Users\\hp\\AppData\\Local\\Programs\\Python\\Python38\\python.exe",
"window.zoomLevel": 0,

"timeline.pageSize": 1,
"terminal.integrated.shell.windows": "",
"code-runner.runInTerminal": true,
"code-runner.executorMap": {

    "cpp": "g++ *.cpp -o $fileNameWithoutExt && ./$fileNameWithoutExt.exe",


},
"code-runner.ignoreSelection": true,
"code-runner.languageIdToFileExtensionMap": {


},
"code-runner.defaultLanguage": "C++",
"terminal.integrated.automationShell.windows": "",

}

2 Answers

This worked for me

"cpp": "cd $dir ; g++ $fileName -o $fileNameWithoutExt.exe ; .\\$fileNameWithoutExt.exe",

If you are a beginner in programming and learning to code in C++ on a windows machine, i recommend to start with a more simpler ide like turbo C++ or dev C++, etc. After this you can switch to codeblocks ide or if you want, directly to vs code.

Coming to your problem, i also faced the same problem on my macbook(i also write C++ in vs code on mac) and i managed to fix it by just reinstalling the extension, however since you are on windows, it should be much easier for you to figure it out. Just do some youtube research about the installation and it should be fine.

Related