【发布时间】:2021-02-04 14:43:57
【问题描述】:
我正在尝试在 VS Code 中调试我的代码。当我“运行”代码(右上角的按钮或 Ctrl+Alt+N)时,它运行良好。但是当我尝试调试时,代码转到 flow==NULL 选项。
这是我的代码阅读功能:
AVLTree readData(char* file_name){
AVLTree myTree;
myTree = CreateTree();
/* Opening file stream for reading data from the file */
FILE* flow;
flow = fopen(file_name,"r");
if(flow==NULL){
printf("\nflow == NULL option\n");
printf("File Error"); exit(1);
}
else{
printf("File opened successfully\n");
}
这也是我的launch.json:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "gcc.exe - Etkin dosyayı derle ve dosyada hata ayıkla",
"type": "cppdbg",
"request": "launch",
// "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"program": "${fileDirname}\\indexingphotos.exe",
"args": [],
"stopAtEntry": false,
"cwd": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "gdb için düzgün yazdırmayı etkinleştir",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc.exe etkin dosyayı derle"
}
]
}
我该怎么办?
另外,我是一名计算机工程专业的学生,直到现在我一直在使用 Dev C++。我正在尝试切换到 VS CODE,但它似乎比 Dev C++ 更令人困惑。我如何学习使用 VS Code(或其他现代 IDE)有什么建议吗?
【问题讨论】:
-
如果找不到该文件,那么可能程序是在错误的目录中启动的。使用绝对路径或 cd 到程序中的正确目录。
-
我该怎么做?能解释一下吗,谢谢。
-
您使用的输入文件的路径可能是相对的。如果是这样,请确保您的程序在同一目录中以“运行”和“调试”模式启动,以便路径正确识别文件; - 或 - 使用文件的绝对路径,以便无论程序的当前目录是什么都可以找到它。
标签: c visual-studio-code vscode-debugger