| | |
Replacing system("pause"); with a function
![]() |
•
•
Join Date: Dec 2007
Posts: 41
Reputation:
Solved Threads: 0
I hear alot of people saying not use:
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.
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!! ^_^
C++ Syntax (Toggle Plain Text)
system("pause"); system("cls"); 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.
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <conio.h> void PrsAnyKey2Cont (); char KeyStroke; void PrsAnyKey2Cont () { cout << "Press any key to continue . . .\n"; KeyStroke = getch (); KeyStroke = getch (); switch (KeyStroke) { default : break; } } int main () { cout << "Hello world!!" << endl; PrsAnyKey2Cont (); return 0; }
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!! ^_^
•
•
Join Date: Dec 2007
Posts: 41
Reputation:
Solved Threads: 0
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: at the beginning of all of my programs for almost 2 years and I've never learned what it meant. Sorry. =[
C++ Syntax (Toggle Plain Text)
using namespace std;
•
•
Join Date: Oct 2006
Posts: 90
Reputation:
Solved Threads: 1
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...)
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...
![]() |
Other Threads in the C++ Forum
- Previous Thread: Programming student find distances btwn cities using array of structs
- Next Thread: clear screen
| Thread Tools | Search this Thread |
api application array based binary bitmap c# c++ c/c++ char class classes code coding compile compression console conversion count cpm delayload delete deploy deque desktop developer dialog directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer introductory java lib linkedlist linkednodes linker loop looping loops map math matrix memory multiple news node numbertoword output pointer problem program programming project python random read recursion reference rpg security sorting string strings temperature template test text text-file tree url variable vector video whyisthiscodecausingsegmentationfault win32 windows winsock wordfrequency wxwidgets






