Jump to content
  • Advertisement
Sign in to follow this  
FinalSmash

Pausing the console in C++?

This topic is 3491 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, new here but not exactly an absolute beginner. I have already taught myself all the basic keywords of the C and CPP language and i want to program in CPP and then to know Java. is there a better way to pause the console in CPP rather than calling system("PAUSE > NUL"); because i know that system() is a C function. how would i write this program truly in CPP?
#include <iostream>

using namespace std;

int main(void)
{
	cout << "This message is 35 characters long." << endl;
	system("PAUSE > NUL");
	system("CLS");
	system("PAUSE");
	return 0;
}
Just an example. this program works, but I've heard system() is deprecated or something. Also what is the stuff inside the main() parenthesis, i know my programs work without the arguments but then what do they do? Final Question while I'm at it... does any1 have a "general purpose steps list" for making games, from conception to final product. what i mean is what are the steps that have to be completed to complete a project. I am often stuck on the conception stage for most of my ideas.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by FinalSmash
is there a better way to pause the console in CPP rather than calling

system("PAUSE > NUL");

because i know that system() is a C function.

how would i write this program truly in CPP?



cin.get();

Share this post


Link to post
Share on other sites
i know that function cin.get() "gets" un-formatted text from the the user and i know it effectively pauses the console, but isn't there a functiopn solely for pausing the console? or is that it?


EDIT: now my program exits or doesn't pause when i type something then hit enter. (i want the function to pause until any key press)

#include <iostream>

using namespace std;

int main(void)
{
cout << "This message is 35 characters long." << endl;
cin.get();
system("CLS");
cin.get();
return 0;
}

Share this post


Link to post
Share on other sites
Quote:
Also what is the stuff inside the main() parenthesis, i know my programs work without the arguments but then what do they do?
If you're talking about (e.g.) 'argc' and 'argv', they convey information about the (optional) command-line arguments that a C++ program can receive when launched. IIRC (I don't use them very often myself), 'argc' is the number of arguments received, and 'argv' is an array of char pointers that contains the actual arguments in C-string form.

When you execute a C++ program from the console, you can write something like the following:
my_program hello how are you
'hello', 'how', 'are', and 'you' will then be stored in the command-line argument array (possibly along with additional arguments supplied by the calling environment).

I believe some IDEs allow you to specify the command-line arguments that the application will receive when run, so that you can customize the behavior of the application 'on the fly', as it were, for testing purposes. If you don't intend to make use of the arguments, however, you can just use the function signature int main(), as you are doing.

Share this post


Link to post
Share on other sites
okay, thanks for that.

what C++ function is equivalent to system("CLS");

i need the console output screen empty at some points in the programs i write.

Share this post


Link to post
Share on other sites
Quote:
Original post by jyk

When you execute a C++ program from the console, you can write something like the following:

my_program hello how are you
'hello', 'how', 'are', and 'you' will then be stored in the command-line argument array (possibly along with additional arguments supplied by the calling environment).


"my_program" is also stored in argv. It would be argv[0]="my_program", argv[1]="hello", argv[2]="how", etc

Quote:
Original post by FinalSmash
what C++ function is equivalent to system("CLS");

i need the console output screen empty at some points in the programs i write.


C++ doesn't have anything to do this (afaik.) I think the best you can get with plain C++ is just outputting a bunch of newlines to the screen. You may want to check the Windows console functions to see if there's anything in there that'll do what you want.

Share this post


Link to post
Share on other sites
Quote:
Original post by FinalSmash
okay, thanks for that.

what C++ function is equivalent to system("CLS");.


There isn't one. You need to use OS-specific calls (which cls is anyway). Read this for Windows:

http://msdn.microsoft.com/en-us/library/ms682022(VS.85).aspx

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!