반응형

터미널의 특정 위치에 문자열을 출력하는 방법을 다루고 있습니다. 



2020. 12. 10 최초작성

 

#include <iostream>
#include <string>
#include <stdarg.h>


void printToCoordinates(int y, int x, const char* format, ...)
{
    va_list args;
    va_start(args, format);
    printf("\033[%d;%dH", y, x);
    vprintf(format, args);
    va_end(args);
    fflush(stdout);
}

int main()
{
#ifdef _MSC_VER
    system("cls");
#else
    system("clear");
#endif

    for ( int i=0; i<1000000; i++)
    {
        printToCoordinates(5, 10, "a1 %d", i);
        printToCoordinates(7, 10, "a2 %d", i);
        printToCoordinates(9, 10, "a3 %d", i);

    }

    return 0;

}





Visual Studio에서 생성한 콘솔 프로그램과 Ubuntu에서 동일하게 동작합니다.

 

 




참고 

 

https://stackoverflow.com/a/1670910



반응형

문제 발생시 지나치지 마시고 댓글 남겨주시면 가능한 빨리 답장드립니다.

도움이 되셨다면 토스아이디로 후원해주세요.
https://toss.me/momo2024


제가 쓴 책도 한번 검토해보세요 ^^

+ Recent posts