How to set output console width in Visual Studio

前端 未结 3 1582
无人共我
无人共我 2021-02-13 10:12

Whenever I build and run my C++ code from Visual Studio 2013, the console window width is un-adjustable and because of this, causes my output to be pushed onto the next line soo

3条回答
  •  故里飘歌
    2021-02-13 10:55

    1. Use Console::SetWindowSize() method (under .NET framework).

      You can refer to here for its documentation and code examples.

    2. Or you can use MoveWindow() method (you can also move the window):

      #include 
      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
      
          // ...
      }
      

      Check out here for more information.


    If you really want to make your code as portable as possible, maybe you should manually set it by running a cmd prompt. Click on the icon at the top. Select defaults. Enter the settings you want.

提交回复
热议问题