Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > BOOK: Ivor Horton's Beginning Visual C++ 2012
|
BOOK: Ivor Horton's Beginning Visual C++ 2012
This is the forum to discuss the Wrox book Ivor Horton's Beginning Visual C++ 2012 by Ivor Horton; ISBN: 978-1-118-36808-4
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Ivor Horton's Beginning Visual C++ 2012 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 23rd, 2013, 05:19 PM
Registered User
 
Join Date: May 2013
Posts: 2
Thanks: 0
Thanked 1 Time in 1 Post
Default Keep Consule Apps from closing after the code is executed.

I read Alex's problem, and I had this same problem as well.

I have found a that you can write getchar(); right before the return 0; command and it will stall the code until you push a button.

for example with Ex1_2 you can write:


Code:
// Ex1_02.cpp A simple console program
#include <iostream>                    // Basic input and output library
        
int main()
{
  std::cout << "This is a simple program that outputs some text." << std::endl;
  std::cout << "You can output more lines of text" << std::endl;
  std::cout << "just by repeating the output statement like this." << std::endl;
  getchar();                          // asks for a char, and then 
  return 0;                            // Return to the operating system
}
I am not certain that this is the best approach, but it has worked well for me; you can read more about the getchar() function at http://msdn.microsoft.com/en-us/libr...v=vs.110).aspx

I hope this was helpful!

Also, if you refer Figure 1-9 on pg.16 you see that "Press any key to continue..." if you know how to make the console do this, please let me know
 
Old May 25th, 2013, 10:41 PM
Registered User
 
Join Date: May 2013
Posts: 2
Thanks: 0
Thanked 1 Time in 1 Post
Default

After working with Visual Studios 2012, a little while I realize that there is a better way to keep console apps from exiting the console as soon as the code is executed. If you go to the menu Debug --> Start Without Debugging or equivalently Ctrl + F5, then the console will prompt you to press enter before is close the console.
The Following User Says Thank You to Curtis0112358 For This Useful Post:
 
Old June 18th, 2013, 10:18 AM
Registered User
 
Join Date: Jun 2013
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Pausing the Console Output Window

I use this: system("PAUSE");
Haven't had a problem with this so far.
Or you can use this line twice:
cin.ignore();
cin.ignore();
the first one flushes the last character from the buffer, the next one waits for a key to be pushed.





Similar Threads
Thread Thread Starter Forum Replies Last Post
VBScript Sub is executed twice.... jaijavan20194 VBScript 4 April 30th, 2009 09:05 PM
Beginning C# Web Apps - Where's the Source Code??? nebulus All Other Wrox Books 3 April 6th, 2009 09:31 AM
why is this code executed twice? hertendreef ASP.NET 2.0 Basics 1 February 23rd, 2007 06:05 AM
IsPostback executed twice amantona ASP.NET 1.0 and 1.1 Professional 3 February 3rd, 2005 08:41 AM
question about closing a modal form using code N2hockey19 Beginning VB 6 1 December 10th, 2003 08:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.