本文介绍了FreeConsole,然后AttachConsole无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在Windows上使用Visual Studio 2013中的C ++控制台应用程序工作。 首先,我使用FreeConsole分离了控制台,它可以正常工作;然后,我尝试使用AttachConsole将其附加回去,但是什么也没发生- #include< psapi.h> DWORD winpid = GetCurrentProcessId(); //获得pid std :: cout<< winpid; //它可以正常工作 FreeConsole(); //控制台丢失了 std :: cout<< 丢到位桶; //没有任何反应,正如预期的那样 AttachConsole(winpid); //尝试找到控制台.... std :: cout<< C; // ...但是失败了 我怎么能找回丢失的控制台?解决方案调用FreeConsole()时,控制台将不复存在。您无法调用AttachConsole(),因为没有要附加的内容。您应该改为使用AllocConsole()创建一个新的控制台,然后像这样附加它: AllocConsole(); 文件* f; freopen_s(& f, CONOUT $, w,标准输出); 然后稍后释放控制台: fclose(f); FreeConsole(); I'm working with a C++ Console Application in Visual Studio 2013, working on Windows.First I detached the console using FreeConsole, it works; then, I tried to attach it back using AttachConsole, but nothing happened -- #include <psapi.h>DWORD winpid = GetCurrentProcessId(); // get pidstd::cout << winpid; // it works FreeConsole(); // console loststd::cout << "Lost to the bit bucket"; //nothing happen, as expectedAttachConsole(winpid); // try find the console back....std::cout << "c"; // ... but failedHow could I find the lost Console back? 解决方案 When you called FreeConsole(), your console ceases to exist. You cannot call AttachConsole() because there is nothing to attach to. You should instead use AllocConsole() to create a new console and then "attach" to it like so:AllocConsole();FILE* f;freopen_s(&f, "CONOUT$", "w", stdout);Then to free the console later on:fclose(f);FreeConsole(); 这篇关于FreeConsole,然后AttachConsole无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-16 10:07