Search code examples
visual-c++c++-cliclr

I'm Trying to print my square on the middle of the console


Why i cant draw my square on the middle of the console? what do i need to change? it jut prints the first line, please help, thanks.

#include "stdafx.h"
#include "iostream"
#include "conio.h"


 using namespace System;
 using namespace std;


 void DibujaCuadrado()
{
 for (int f=1;f<=5;f++)
   {
    for (int c=1; c<=5;c++)
    {
        cout << "O";
    }
    cout << endl;
  }
}

int main()
{
Console::SetWindowSize(80, 40);
Console::SetCursorPosition(40, 20);
DibujaCuadrado();

_getch();
return 0;
}

Solution

  • You are using both standard C++ console output as well as CLR System::Console namespace cursor positioning. The std::endl will reset the cursor position to the left hand side. You probably want to reset the cursor position after each f-for loop maybe using Console::CursorLeft = 40;.