[英]C++ type cast operator code that won't compile in visual studio 2012, but worked fine in visual studio 2005
[英]My C++ program won't compile on Visual Studio code
我第一次嘗試使用 Visual Studio Code,但我的 C++ 無法編譯。
我已經將 mingw 的 bin 和 bash.exe 從 MSYS2 添加到我的 PATH。 我的所有代碼都在同一個目錄中,直接來自微軟的指南https://code.visualstudio.com/docs/cpp/config-mingw (我確實改變了我的路徑)。 我的所有文件也都在同一目錄中。
我已經包含了文件
你好世界.cpp:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World";
}
任務.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "build hello world",
"type": "shell",
"command": "g++",
"args": [
"-g",
"-o",
"helloworld",
"helloworld.cpp"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
c_cpp_properties.json:
{
"configurations": [
{
"name": "Win32",
"defines": [
"_DEBUG",
"UNICODE"
],
"compilerPath": "C:\\Mingw-w64\\mingw32\\bin\\g++.exe",
"intelliSenseMode": "gcc-x64",
"browse": {
"path": [
"${workspaceFolder}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 4
}
啟動.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/helloworld.exe",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Mingw-w64\\mingw32\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
該文件不會構建,我不斷收到相同的錯誤消息:
g++.exe:錯誤:helloworld.cpp:沒有那個文件或目錄 g++.exe:致命錯誤:沒有輸入文件編譯終止。 終端進程以退出代碼終止:1
似乎編譯器無法定位源文件,更新tasks.json以編譯具有完整路徑的程序,
{
"version": "2.0.0",
"tasks": [
{
"label": "build hello world",
"type": "shell",
"command": "g++",
"args": [
"-g",
"${file}",//Just
"-o",//edit
"${workspaceFolder}\\${fileBasenameNoExtension}"//these
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
這里${file}
給出了帶有擴展名 (.cpp) 的文件的完整路徑, ${workspaceFolder}
和${fileBasenameNoExtension}
也幾乎不言自明。
That eventually worked after I exited the shell and re-opened it
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "echo",
"type": "shell",
"command": "g++",
"args": [
"-g", "main.cpp"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.