简体   繁体   中英

C++ not running in vs code

I am trying to run my C++ code in vs code. I have installed global extension for C/C++ by Microsoft and also code runner extension. When I run my code it shows this in the terminal.

user@LAPTOP-7LH95TTK MINGW64 ~/Desktop
$ cd "c:\Users\user\Desktop\" && g++ demo.cpp -o demo && "c:\Users\user\Desktop\"demo
bash: cd: c:\Users\user\Desktop" && g++ demo.cpp -o demo && c:UsersuserDesktop"demo: No such file or directory

What should I do ? I think the default command that shows up in the terminal when I run my code is incorrect and I don't know how to change it.

Below is the code from demo.cpp file

#include<bits/stdc++.h>
using namespace std;
int main(){
    cout<<"Hello everyone"<<endl;
    return 0;
}

You can read through https://code.visualstudio.com/docs/cpp/config-mingw (if using MinGw).

If you have MSVC (MS C++ Compiler) installed, instead of 'g++' command you would be using the 'cl' command to compile (the guide for that is at https://code.visualstudio.com/docs/cpp/config-msvc ).

Just a brief of the article:

You should have a tasks.json file inside .vscode.

It is the file that is used for instructions to build your code

And, there can be a launch.json also, that is used by VS Code for instructions to debug it. (Not Required)

What i generally do, is click this "Create a launch.json" in the Debug tab, which will ask you to chose the toolchain (compiler,...), and create tasks.json, and launch.json for you.

You can then just use "Shift+Ctrl+B" (default), to just build the code. The debugging option is just a plus, you will require sooner or later :D

创建一个launch.json文件

1.I think you should downlaod Mingw gcc compiler and install in your system 
 properly step by step.
  2.click on Advance setting by right click on My Pc
 3.click on Environment Varaible
 4. move to System Variable there
 5. take cursor on PATH click
 6.click on Edit
 7. click New
 8.copy the C:\Mingw\bin or where u have installed
 9. Move the new Path to Top
 10.Click ok
  Your problem Solved

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM