How to move a character from left to right on the console screen in C++

1 Answer

0 votes
#include <iostream>
#include <chrono>
#include <thread>
 
int main() {
    const int width = 50;
 
    for (int x = 0; x < width; x++) {
        std::cout << "\r";              // return to line start
        std::cout << std::string(x, ' ') << '@';  // move @ to position x
        std::cout.flush();              // force output
        std::this_thread::sleep_for(std::chrono::milliseconds(80));
    }
}
 
 
 
/*
run:
 
                       @
 
*/

 



answered 13 hours ago by avibootz
edited 2 hours ago by avibootz
...