I\'m trying to print characters in the console at specified coordinates. Up to now I have been using the very ugly printf(\"\\033[%d;%dH%s\\n\", 2, 2, \"str\");
A few improvements to your function:
void printToCoordinates(int x, int y, const char *format, ...)
{
va_list args;
va_start(args, format);
printf("\033[%d;%dH", x, y);
vprintf(format, args);
va_end(args);
fflush(stdout);
}
This version:
stdout without printing a newlinex and y in the format string (your use of x and x may have been a typo)However, because varargs is essentially a C feature and doesn't really understand C++ objects, you'd have to call it like this:
printToCoordinates(10, 10, "%s", text.c_str());
A better option really is to use curses (for Unix-like platforms) or Win32 console functions (for Windows) as mentioned in other answers.