Last active
February 2, 2023 21:45
-
-
Save bathoryr/158a306319ef9687e3ee86c3eab99918 to your computer and use it in GitHub Desktop.
Windows console iostream positioning manipulator std::pos(x, y)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Windows.h> | |
#include <iostream> | |
namespace std | |
{ | |
struct _pos | |
{ | |
_pos(short x, short y) : _x(x), _y(y) | |
{} | |
template<typename Elem, typename Traits> | |
friend std::basic_ostream<Elem, Traits>& operator<<(std::basic_ostream<Elem, Traits>& ostr, const _pos& manip) | |
{ | |
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), COORD{manip._x, manip._y}); | |
return ostr; | |
} | |
private: | |
short _x, _y; | |
}; | |
_pos pos(short x, short y) | |
{ | |
return _pos(x, y); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Set cursor position on Windows console when using std::cout operator << and manipulator std::pos(x, y)