I''ve played with this for some time and I can not get this command to work...any ideas out there? Thanks.
C++ Command Prompt Question
A couple more questions concerns that I have....
I wrote this program just to experiment with a few things:
/************************************/
//libraries
#include <iostream>
#include <stdlib.h>
//introduces namespace std
using namespace std;
void wait(float f_secs);
void print_out(string printer);
void clean();
int main( void )
{
print_out("Randomness...");
wait(1.1);
system("clear"); //come on....
system("cls"); //please....
clean();
print_out("Work now...");
cin.get();
}
void wait(float f_secs)
{
float secs = f_secs;
clock_t delay = secs * CLOCKS_PER_SEC;
clock_t start = clock();
while(clock() - start < delay)
{}
}
void print_out(string printer)
{
cout<
}
void clean()
{
cout<<"\n";
system("clean"); //i give up
}
/************************************/
My primary concerns (if anyone cares out there):
1)As you can see I can not get system("cls") to work nor "clean" or "clear" as others have suggested (all do nothing). I know it is not XP as I have tried this also on my 98se machine at work. Could it be my compiler (Metrowerks Codewarrior 5, no flames please), though I see no reason why....
2)I found this wait function example in one of my files from a ways back when I was getting into c++ but I can not remember much about it other than the obvious result and a few obscurities floating about in my mind...can anyone give me a quick rundown of the lines? (sad I know) I don''t want to use it again without being absolutely comfortable with its workings.
3)This really should be in q 2 but...I noticed that if I tried to cout "Randomness..." in a line without putting it in a function it would come after the wait not before...why is that?
More than many thanks ahead of time!
I wrote this program just to experiment with a few things:
/************************************/
//libraries
#include <iostream>
#include <stdlib.h>
//introduces namespace std
using namespace std;
void wait(float f_secs);
void print_out(string printer);
void clean();
int main( void )
{
print_out("Randomness...");
wait(1.1);
system("clear"); //come on....
system("cls"); //please....
clean();
print_out("Work now...");
cin.get();
}
void wait(float f_secs)
{
float secs = f_secs;
clock_t delay = secs * CLOCKS_PER_SEC;
clock_t start = clock();
while(clock() - start < delay)
{}
}
void print_out(string printer)
{
cout<
}
void clean()
{
cout<<"\n";
system("clean"); //i give up
}
/************************************/
My primary concerns (if anyone cares out there):
1)As you can see I can not get system("cls") to work nor "clean" or "clear" as others have suggested (all do nothing). I know it is not XP as I have tried this also on my 98se machine at work. Could it be my compiler (Metrowerks Codewarrior 5, no flames please), though I see no reason why....
2)I found this wait function example in one of my files from a ways back when I was getting into c++ but I can not remember much about it other than the obvious result and a few obscurities floating about in my mind...can anyone give me a quick rundown of the lines? (sad I know) I don''t want to use it again without being absolutely comfortable with its workings.
3)This really should be in q 2 but...I noticed that if I tried to cout "Randomness..." in a line without putting it in a function it would come after the wait not before...why is that?
More than many thanks ahead of time!
1. I suppose so, seeing how I''ve never heard of that compiler...
2.I don''t get it either, I suggest that if you want to wait, use sleep() (I think thats what its called...it might be comething else though. You need windows.h to use it; it sleeps by the milliseconds aka sending 1000 as the argument would sleep for 1 second)
If you REALLY want to write your own function to sleep (for self-gratification), I recommend something easier (include time.h, then call time(); it returns a number in seconds, if that helps)
3.AHA! Many newbies often get confused by this. This has to do with the way COUT works. See, when you input something, it gets sent to the....thingy (buffer?), where it waits to be sent to the outputscreen. Everything from cout is stored into that...thingy (buffer?) until something FLUSHES it. To FLUSH means to...umm...flush out of from the...thingy...and into the console (where its displayed as whatever you sent it, usually text). The thingy is then empty, and the screen has its output.
I know of several ways to flush the buffer. First of all, calling using endl with an output stream (this thing <<), or using cin with the input stream (this thing >>) flushes the buffer (so you can just add "<< endl" to the end of you cout statement, and it should work). Another way is to flush with thet output (<<) stream (so you could just add "<< flush" to the end of your cout statement, and it would flush without going down a line). The last way I know is to call cout.flush() (which does the same thing as "<< flush", but it looks cooler)
I see you never finished your printout() function, so I''ll do it for you (to show you what it should look like)
"I''ve learned something today: It doesn''t matter if you''re white, or if you''re black...the only color that REALLY matters is green"
-Peter Griffin
2.I don''t get it either, I suggest that if you want to wait, use sleep() (I think thats what its called...it might be comething else though. You need windows.h to use it; it sleeps by the milliseconds aka sending 1000 as the argument would sleep for 1 second)
If you REALLY want to write your own function to sleep (for self-gratification), I recommend something easier (include time.h, then call time(); it returns a number in seconds, if that helps)
3.AHA! Many newbies often get confused by this. This has to do with the way COUT works. See, when you input something, it gets sent to the....thingy (buffer?), where it waits to be sent to the outputscreen. Everything from cout is stored into that...thingy (buffer?) until something FLUSHES it. To FLUSH means to...umm...flush out of from the...thingy...and into the console (where its displayed as whatever you sent it, usually text). The thingy is then empty, and the screen has its output.
I know of several ways to flush the buffer. First of all, calling using endl with an output stream (this thing <<), or using cin with the input stream (this thing >>) flushes the buffer (so you can just add "<< endl" to the end of you cout statement, and it should work). Another way is to flush with thet output (<<) stream (so you could just add "<< flush" to the end of your cout statement, and it would flush without going down a line). The last way I know is to call cout.flush() (which does the same thing as "<< flush", but it looks cooler)
I see you never finished your printout() function, so I''ll do it for you (to show you what it should look like)
void print_out(string printThis)//Doesn''t Printer call the cout to the printer? Or was there another iostream object for that? I can''t remember, I only read breifly about it in a book once.//...Just to be safe, I''m gonna change the name of the string printer to printThis.{cout << printThis << flush;}
"I''ve learned something today: It doesn''t matter if you''re white, or if you''re black...the only color that REALLY matters is green"
-Peter Griffin
"I've learned something today: It doesn't matter if you're white, or if you're black...the only color that really matters is green"-Peter Griffin
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement