Replacing system("pause"); with a function

Reply

Join Date: Dec 2007
Posts: 41
Reputation: #include<DAN.h> is an unknown quantity at this point 
Solved Threads: 0
#include<DAN.h> #include<DAN.h> is offline Offline
Light Poster

Replacing system("pause"); with a function

 
0
  #1
Jan 14th, 2008
I hear alot of people saying not use:
  1. system("pause");
  2. system("cls");
  3. system("title");

I think you get what I mean, so I'm trying to make functions that will replace all of these, and for my first installment I'm going to show you how to replace system("pause");. Here is what I have.

  1. #include <iostream>
  2. #include <conio.h>
  3.  
  4. void PrsAnyKey2Cont ();
  5. char KeyStroke;
  6.  
  7. void PrsAnyKey2Cont ()
  8. {
  9. cout << "Press any key to continue . . .\n";
  10. KeyStroke = getch ();
  11. KeyStroke = getch ();
  12. switch (KeyStroke)
  13. {
  14. default :
  15. break;
  16. }
  17. }
  18.  
  19. int main ()
  20. {
  21. cout << "Hello world!!" << endl;
  22. PrsAnyKey2Cont ();
  23. return 0;
  24. }

There are probably a million things wrong with this right now and I plan on making a better function that will allow you to set the time of the pause and wether or not the user even needs to input a key to continue. Thanks for any constructive critisism!! ^_^
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,540
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 704
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Replacing system("pause"); with a function

 
0
  #2
Jan 14th, 2008
>Thanks for any constructive critisism!!
PrsAnyKey2Cont is a very awkward name.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 41
Reputation: #include<DAN.h> is an unknown quantity at this point 
Solved Threads: 0
#include<DAN.h> #include<DAN.h> is offline Offline
Light Poster

Re: Replacing system("pause"); with a function

 
0
  #3
Jan 14th, 2008
Yeah, I know, but I couldn't think of anything short and descriptive. XD Do you have any seggestions for a better name?
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,540
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 704
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Replacing system("pause"); with a function

 
0
  #4
Jan 14th, 2008
>Do you have any seggestions for a better name?
At the risk of borrowing an existing name, "pause" is short and sweet. Throwing it in a "console" namespace is descriptive, and I can type and read console::pause so much faster than PrsAnyKey2Cont.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 41
Reputation: #include<DAN.h> is an unknown quantity at this point 
Solved Threads: 0
#include<DAN.h> #include<DAN.h> is offline Offline
Light Poster

Re: Replacing system("pause"); with a function

 
0
  #5
Jan 14th, 2008
Excuse me for sounding like a total noob here for a second, but what is a "console namespace". To tell you the truth I've been writing:
  1. using namespace std;
at the beginning of all of my programs for almost 2 years and I've never learned what it meant. Sorry. =[
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 90
Reputation: Brent.tc is an unknown quantity at this point 
Solved Threads: 1
Brent.tc Brent.tc is offline Offline
Junior Poster in Training

Re: Replacing system("pause"); with a function

 
0
  #6
Jan 14th, 2008
I BELIEVE that a namespace is just something used to give context to where something should be used. Also, it helps to avoid conflicting names.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 41
Reputation: #include<DAN.h> is an unknown quantity at this point 
Solved Threads: 0
#include<DAN.h> #include<DAN.h> is offline Offline
Light Poster

Re: Replacing system("pause"); with a function

 
0
  #7
Jan 14th, 2008
So, what does it mean to say std::pause?
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 90
Reputation: Brent.tc is an unknown quantity at this point 
Solved Threads: 1
Brent.tc Brent.tc is offline Offline
Junior Poster in Training

Re: Replacing system("pause"); with a function

 
0
  #8
Jan 14th, 2008
Is there a pause in std? do you mean std::system("pause") ?
Well anyways, since 'pause' is/would be in namespace std, you must first 'access' the std namespace.

Think of it as a box where you put things to keep them either organized, or from getting jumbled with other things. You can't simply remove something from the box without first opening the box... (Said box has a lid...)
Last edited by Brent.tc; Jan 14th, 2008 at 6:42 pm. Reason: Spell check...
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 41
Reputation: #include<DAN.h> is an unknown quantity at this point 
Solved Threads: 0
#include<DAN.h> #include<DAN.h> is offline Offline
Light Poster

Re: Replacing system("pause"); with a function

 
0
  #9
Jan 14th, 2008
Yeah I just forgot to put using namespace std;, which would open the box, right?
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 90
Reputation: Brent.tc is an unknown quantity at this point 
Solved Threads: 1
Brent.tc Brent.tc is offline Offline
Junior Poster in Training

Re: Replacing system("pause"); with a function

 
0
  #10
Jan 14th, 2008
More like dumping the box all over the floor... Because once the box is opened (using namespace std; ) you no longer have to open it each time you want something from it (std:wantedObject)
Last edited by Brent.tc; Jan 14th, 2008 at 7:32 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC