提问人:PikaCiung 提问时间:5/5/2023 最后编辑:UpAndAdamPikaCiung 更新时间:5/6/2023 访问量:106
为什么 VSCode 无法读取与打开的文件位于同一目录中的文件?
Why is VSCode not able to read from files in the same directory as the opened file?
问:
我已经搜索了这个并尝试了多种launch.json和tasks.json配置,但似乎没有任何效果。当我从控制台读取时,我用 c++ 编写的程序可以正常工作,因此问题不在于原始代码。我尝试过多个程序,但从未能够让它从文件中读取。我希望你能帮上忙。 这是我launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++: gcc.exe build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"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
},
],
}
],
"preLaunchTask": "C/C++: gcc.exe build active file"
}
这是我tasks.json:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\Program Files\\CodeBlocks\\MinGW\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\Program Files\\CodeBlocks\\MinGW\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
例如,文件“bac.in”包含数字 。
运行此程序时,控制台显示 0 而不是 144:1 7 2 1 1 2 1 7 2
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("bac.in");
int a[10];
int main()
{
int S=0, i;
while ( fin >> i )
{
if ( a[i] == 0 )
{
a[i]= 1;
S += 10;
}
S += i*i;
}
cout << S;
return 0;
}
答: 暂无答案
评论
"cwd": "${fileDirname}",
应该处理的。tasks.json
launch.json
bac.in
bac.in.txt