The most annoying thing about using Visual Studio Code to write C++ programs is that the Code Runner plug-in can’t compile and run files with spaces in the file name. This problem has troubled me for a long time. Although it does not affect my learning, too many separators always feel unpleasant. So I studied it carefully.
First create a test program called “hello world”, and then analyze the reason based on the G++ error report in English:
g++.exe: error: hello: No such file or directory
g++.exe: error: world.cpp: No such file or directory
g++.exe: error: world: No such file or directory
g++.exe: fatal error: no input files
compilation terminated.
No such file or directory
It means that there is no such file or directory, fatal error: no input files
which means a fatal error: there is no input file, and then the compilation has been terminated. According to error, we found that the C ++ compiler is hello world.cpp
as the hello
and world.cpp
the two documents, my first reaction is the filename with spaces to be enclosed in double quotes. Go to the Code Runner plug-in page, click Settings -> Extended Settings.
After that, find Executor Map and click to edit in setting.json.
Find “cpp” and change it to:
"cpp": "cd $dir && g++ \"$fileName\" -o \"$fileNameWithoutExt.exe\" && \"$fileNameWithoutExt.exe\"",
Run hello world.cpp
, the compilation is successful, but how to output the file name? I tested it in CMD again. It was able to compile and run the program. The problem was immediately locked in Powershell. I thought that the code of the CMD and Powershell running program must be different, so the failure occurred.
After searching for Baidu, I found out that Powershell should add the symbol (&) in front of it. This is called a call operation.
After adding &, an error message appears again:
It turned out to be added with “.”. The final compile and run code becomes:
"cpp": "cd $dir && g++ \"$fileName\" -o \"$fileNameWithoutExt.exe\" && & \".\\$fileNameWithoutExt.exe\"",
Similar Posts:
- Eclipse C/C++ Error: launch failed,binary not found
- How to Solve Warning: No mapping found for HTTP request with URI [] in DispatcherServlet with name
- Ubuntu16.04 Install python-ldap error: command ‘x86_64-linux-gnu-gcc’ failed with exit status 1
- SVN Error: ‘you’ is not valid as filename in directory [How to Solve]
- Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1
- Solve the problem of link: fatal error LNK1104: unable to open the file “d3dx9. Lib”
- [Solved] TSC Compile TS File Error: TSC: the file cannot be loaded because running scripts is prohibited on this system;
- fatal error C1010: unexpected end of file while…
- [Solved] Go Gcc Compilation Error: gcc.exe fatal error no input files compilation terminated
- Linux Error: _mysql.c:32:20: fatal error: Python.h: No such file or directory [Solved]