Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Timing question

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
ok now im in the right forum:)

Using this code,


void main()
{ string A,B,C;
A="hello";
B="how are you";
C="what is your name?";

cout<<A<<endl;
cout<<B<<endl;
cout<<C<<endl;
}

its going to display like this,
hello
how are you
what is your name?

My question is,when C++ display those its going to do it fast enough that its going to look like it was display it all at the same time.

How can I get C++ to display one string and wait maybe 2 seconds then display next string and wait 2 second, go on and on ..ect..ect..

Does anyone have any idea?
 
When I use it I keep getting this error,
: error C2065: 'sleep' : undeclared identifier
Does it need a specific header file or did I misuse it?

Heres where I put it in the code

#include<iostream>
#include<fstream>
using namespace std;

void main()
{
ifstream Infile(&quot;record.txt&quot;);
char Firstline[80]={0},FirstName[80]={0};
int count=0;



Infile.getline(Firstline,80,'\n');
Infile.get(FirstName,80,' ');
cout<<Firstline<<endl;

for( count=0;count<80;count++)
{
cout<<FirstName[count];
sleep(2000);
}




}
 
That's because Sleep is a windows function defined in <winbase.h> on windows systems.
[red]Nosferatu[/red]
We are what we eat...
There's no such thing as free meal...
once stated: methane@personal.ro
 
I use the Winbase.h like you suggested but still get an error,
: fatal error C1083: Cannot open include file: 'winbase': No such file or directory

but when I search for it on my computer that file does exist.
#include<iostream>
#include<fstream>
#include<winbase.h>
using namespace std;

void main()
{
ifstream Infile(&quot;record.txt&quot;);
char Firstline[80]={0},FirstName[80]={0};
int count=0;



Infile.getline(Firstline,80,'\n');
Infile.get(FirstName,80,' ');
cout<<Firstline<<endl;

for( count=0;count<80;count++)
{
cout<<FirstName[count];
sleep(2000);
}




 
Check your include directory path to make sure the directory where winbase.h is located is on it.

In Visual C++, this is in the options dialog.

Chip H.
 
I dont know what to do it doesnt work.
Does anyone know another way to make C++
cout,pause,cout,pause,cout,pause..ect..
to give you an idea, its like a type writer effect.
thanks everyone for your help so far, i really appreciate it.
 
I finally got it to work. I dont think sleep() uses the <winbase> header. I think its <windows.h>. Thankx everyone.
 
well... You're welcome, but Sleep IS defined in WinBase.H, as a matter of fact...
But, it seems that you cannot include directly <winbase>, you have to include <windows.h> before it, which defines the usual windows types used in winbase...
Anyway, glad you could make it... [red]Nosferatu[/red]
We are what we eat...
There's no such thing as free meal...
once stated: methane@personal.ro
 
in a unix system, How can I get C++ to display one string and wait maybe 2 seconds then display next string and wait 2 second, go on and on ..ect..ect..

 
almost the same,

#include <unistd.h>
sleep(2);

or

#include<sys/time.h>
usleep(2000);
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top