本文介绍了如何配置CLion标准控制台输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:
CLion不会出于调试目的而输出任何控制台输出。

Problem:CLion doesn't output any console output for debugging purposes.

我正在将CLion与MingW编译器和cmake。无论我是否使用:

I'm using CLion with the MingW compiler and cmake. No matter whether I use:

std::cout << "Testing" << std::endl;

或:

printf("Testing");

我看不到任何控制台输出。

I don't see any console output.

尝试解决问题的机会

1:
我已经检查了运行,调试,终端和 Cmake。我试图编辑配置,但未显示调试。

1:I've checked "Run", "Debug", "Terminal" and "Cmake". I've attempted to edit my configurations but "Debug" doesn't show up.

2:
接下来,我转到Settings-> Build,Execution,Deployment-> CMake来编辑Generation类型。我添加了Debug和RelWithDebInfo,但仍然无济于事。

2:Next, I went to Settings->Build,Execution,Deployment->CMake to edit the Generation types. I added Debug and RelWithDebInfo and still to no avail.

3:
我也尝试向Cmake添加 -Debug ,但我仍然没有输出。

3:I also attempted to add "-Debug" to Cmake, but I still have no output.

4:
我收到的用于调试的最接近的东西是使用GDB查看断点处的变量值。这仅适用于 RelWithDebInfo世代。

4:The closest thing I've received for debugging is using GDB to view variable values at break points. This only works in the "RelWithDebInfo" generation.

推荐答案

解决方案:

我最终弄清了问题所在。

I ended up figuring out what the problem was.

我正在Windows的CLion中开发Qt GUI应用程序。您必须指定一个控制台,控制台输出才能打印到该控制台上。

I'm developing a Qt GUI application within CLion on Windows. You have to specify a console for console output to print onto.

在您的主机的早期调用此Console()函数以打开控制台提示。现在,无论何时运行

Call this Console() function early in your main for a console prompt to open up. Now, whenever you run

QDebug() << <string>;

std::cout << <string> std::endl;

您将看到调试语句。希望这可以帮助其他有同样问题的人。

You'll see your debugging statements. Hope this helps somebody else out there with the same problem.

代码:

void Console()
{
    AllocConsole();
    FILE *pFileCon = NULL;
    pFileCon = freopen("CONOUT$", "w", stdout);

    COORD coordInfo;
    coordInfo.X = 130;
    coordInfo.Y = 9000;

    SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coordInfo);
    SetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE),ENABLE_QUICK_EDIT_MODE| ENABLE_EXTENDED_FLAGS);
}

资料来源:

我在这里找到了解决方案:
[0]

I found a solution here:[0] Console output in a Qt GUI app?

这篇关于如何配置CLion标准控制台输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 00:08
查看更多