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.

Recommended Answers

All 2 Replies

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

That was it. Thanks a lot!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.