【发布时间】:2020-10-07 02:22:55
【问题描述】:
主函数内的任何 cout 语句在调试期间不打印任何值,但其他函数内的 cout 在函数调用期间打印值(我使用 vscode)
#include<iostream>
using namespace std;
int main()
{
int a;
a=9;
if(a==9)
{
cout<<"hello";}
return 0;
}
当它被调试时,在 main() 的第一行放置一个断点 调试控制台中不打印“hello”。
#include <iostream>
using namespace std;
void fun(int n)
{
if (n > 0)
{
cout << n << endl;
fun(n - 1);
}
}
int main()
{
int x = 3;
fun(3);
cout<<x;
return 0;
}
但是当通过在 main() 的第一行放置断点来调试时 值打印为 3 2 1
【问题讨论】:
-
“其他功能”的打印效果如何?请花一些时间阅读the help pages,阅读SO tour,阅读How to Ask,以及this question checklist。然后edit你的问题来改进它,例如添加一个minimal reproducible example。
-
如果 main 内部有一个函数调用并且它被调用并且其中存在一个 cout ......那个 cout 正在打印一个值
-
我怀疑
main中的打印是在函数调用之后并且您的函数永远不会返回。 -
@KaranarjunJr。你能举个例子吗?
-
请不要描述代码,而是显示给我们。正如我已经提到的,请edit 您的问题包括minimal reproducible example。
标签: c++ debugging visual-studio-code