我尝试在 VS Code 中调试一些代码。一切正常,但是当我尝试在控制台中输入某些内容时,什么也没有发生。
我的代码:
#include <stdio.h>
#define SIZE 20
int main()
{
char arr[SIZE];
fgets(arr, SIZE, stdin);
puts(arr);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我过去常常fgets()从控制台读取字符串,但是当调试到达函数时,一切都会停止,我无法输入任何内容。
只是黑窗。
但是,当我使用 时gets(),就像这个例子一样:
#include <stdio.h>
#define SIZE 20
int main()
{
char arr[SIZE];
gets(arr);
puts(arr);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
一切正常。
哪里有问题?也许调试控制台无法读取任何内容?我怎样才能使用输入任何内容fgets()?
这是我的 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": …Run Code Online (Sandbox Code Playgroud) 我试图按照这篇文章的指示
但是当我将控制台配置添加到launch.json文件时
"console": "integratedTerminal"
Run Code Online (Sandbox Code Playgroud)
它抛出"不允许属性控制台".当我调试程序时,它仍然等待输入,并且永远不会达到断点,就像我开始在shell中一样
"./a.out 1 test1.txt"
"./a.out 1 <test1.txt"
Run Code Online (Sandbox Code Playgroud)
完整配置
{
"version": "0.2.0",
"configurations": [
{
"name": "(lldb) Launch",
"type": "cppdbg",
"request": "launch",
//"program": "${workspaceRoot}/a.out.dSYM/Contents/Resources/DWARF/a.out",
"program": "${workspaceRoot}/a.out",
"args": ["1", "<","test1.txt"],
"stopAtEntry": false,
"cwd": "${workspaceRoot}/",
"environment": [],
"externalConsole": true,
"MIMode": "lldb",
//"miDebuggerPath": "C:\\mingw\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"console": "integratedTerminal"
//"preLaunchTask": //"build test1"
}
]
Run Code Online (Sandbox Code Playgroud)
}
我正在使用VSCode在MacOSX 中调试我的CPP程序。
我有2个程序。
程序1
int main(){
string a;
a = "a";
a += 'b';
cout<<a<<endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
程序2
int main(){
string a;
cin>>a;
a += 'b'
cout<<a;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在program1 中,我直接分配string a和 当我调试程序时VSCode,首先使用以下命令在终端中编译它:
g++ -g filename.cpp
然后在调试菜单中选择开始调试选项。我可以通过在断点中向前移动来查看变量的状态。string a
的变量部分显示不同的变量的状态和CALL堆栈显示堆栈帧。
但是,对于program2,当我越过 的断点时cin>>a;,VARIABLES和CALL STACK的内容将被清除。
以下是launch.json文件的内容:
{
"version": "0.2.0",
"configurations": …Run Code Online (Sandbox Code Playgroud)