0

Hi, I'm trying to create a pretty basic fancy string output,

#include <iostream>
#include <cstring>
#include <stdlib.h>

using namespace std;

int main()
{

        char output[] = "Hello there world";
        int len = strlen(output);
        
        for (int i = 0; i < len; i++)
        
                {

                        cout << output[i];
                        system("sleep 0.1");

                }

return 0;
}

It supposed to write every char separately which it does in windows, but I cant get it tot work in Linux, (g++). Instead it sleeps the total amount of time the loop takes and then writes out the complete sentence.
I've tried the usleep and nanosleep functions as well, but no satisfaction.

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Slacked
1

Buffered output is probably the problem. End the cout line with flush to empty the buffer immediately.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.