How would i go about making a program wait before printing the next line? Keep in mind that i would like the next line to print automatically after a few seconds. Also if at all possible i would like to know how to make the text act like it is typing itself out on the screen.

The most popular method of delay is to use the Sleep() function, a member of the <windows.h> library.

could you give me an example?

#include<iostream>
#include<windows.h>

int main(){
   string str = "hello";
    cout<<str<<" ";
    Sleep(1000); //wait 1 second
     cout<<"world\n";

 return 0;
}

thank you

#include<windows.h>
#include<iostream>
using namespace std;

int main()
{
     char hello[11] = {'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd'};

     for(int i=0, i<11, i++)
     {
          cout.put(hello[i]);
          Sleep(500);
     }
return 0;
}
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.