每当我从Visual Studio 2013构build并运行我的C ++代码时,控制台窗口宽度都是不可调整的,因此,我的输出会比我想要的更快地被推到下一行。
我怎样才能让视觉工作室,使控制台的窗口宽度更大?
如果我需要在我的应用程序中插入代码来做到这一点,是否有一种方法,我可以把一个编译时检查,以便它不删除编译时在Windows上的代码? 我试图使代码尽可能便携。
我经常使用控制台应用程序的一个解决方案我从Visual Studio进行调试,不需要更改代码就是执行以下操作:
关闭对话框后,窗口应保存设置或提示您保存,具体取决于您的Windows版本。 我相信Windows 8或更新版本不会提示,而Windows 7或更低的提示。
使用Console::SetWindowSize()
方法(在.Net框架下)。
你可以参考这里的文档和代码示例。
或者你可以使用MoveWindow()
方法(你也可以移动窗口):
#include <windows.h> using namespace std; int main (void) { HWND console = GetConsoleWindow(); RECT r; GetWindowRect(console, &r); //stores the console's current dimensions MoveWindow(console, r.left, r.top, 800, 100, TRUE); // 800 width, 100 height // ... }
在这里查看更多信息。
编辑:如果你真的想让你的代码尽可能便携,也许你应该通过运行cmd
提示符来手动设置它。 点击顶部的图标。 选择defaults
。 输入你想要的设置。
你可以简单地使用这个:
Console.WindowWidth = Console.LargestWindowWidth - [insert number of pixels from the end of the screen] Console.WindowHeight = Console.LargestWindowHeight - [insert number of pixels from the end of the screen]
如果我想将控制台窗口设置为距屏幕边缘15像素,我会这样做:
Console.WindowWidth = Console.LargestWindowWidth - 15