Black square character improperly shown when rapidly printed

478 views Asked by At

so i made this on repl.it :

#include <iostream>
#include <thread>
#include <chrono>
using namespace std;

int main(){
    for(int i=0; i<100; i++){
        for(int j=0; j<30; j++){
            for(int k=0; k<40; k++){
              cout<<"■"<<' ';
            }
            cout<<endl;
        }
        this_thread::sleep_for(chrono::seconds(1));
        system("clear");
    }
}

Issue

When i run the code, occasionally, exactly 2 characters right next to each other are replaced with the character on mostly the lower half of the output.

Tried:

Replacing the single quote for the space character after the square character with double quote, moving the space character into the square character string:

Result: no observable changes.

Removing the space character:

Result: the issue still exists, but it occurs less frequently.

Reducing the amount j and k iterates:

Result: apparently the characters no longer gets printed, but I doubt if the problem has really been solved (the probability of the issue occurring could have just been lowered to the point that I can't consistently reproduce the problem).

0

There are 0 answers