I cannot create or read files using vscode with fstream. Program run from .exe works normally (creates a file empty.txt). main.cpp:
#include <fstream>
int main()
{
std::ofstream file("empty.txt");
}
The above program does not create a file when run with vscode.
- Editor: Visual Studio Code
- Compiler: MinGW-w64 (MSYS2)
- System: Windows 10
launch.json:
{
"configurations": [
{
"name": "C/C : g .exe build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "C:\\msys64\\mingw64\\bin",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C : g .exe build active file"
}
],
"version": "2.0.0"
}
tasks.json:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C : g .exe build active file",
"command": "C:\\msys64\\mingw64\\bin\\g .exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${fileDirname}\\**.cpp",
//"${fileDirname}\\**.h",
//"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\msys64\\mingw64\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
CodePudding user response:
Change cwd
in both launch.json
and tasks.json
to "cwd": "${workspaceFolder}",
.
See also the official how to.