How to view the output

Z

zinga

Hi,
I am a newbie to programming, I am trying out c++ programs but I wanted to
know how to make the output of the program stay and wait for my command to
terminate.

thanks
Zinga
 
M

Mike Wahler

zinga said:
Hi,
I am a newbie to programming, I am trying out c++ programs but I wanted to
know how to make the output of the program stay and wait for my command to
terminate.

Either run your program from outside your IDE,
or right before main() returns, put a statement
requesting input:

#include <iostream>

int main()
{
std::cout << "Hello\n";
std::cout << "Press ENTER to continue...";
std::cin.get();
return 0;
}

-Mike
 
M

Mike Hewson

zinga said:
Hi,
I am a newbie to programming, I am trying out c++ programs but I wanted to
know how to make the output of the program stay and wait for my command to
terminate.

thanks
Zinga

Unless your IDE doesn't do this ( it might but you may not have found
that yet ), then something like this:

#include <iostream> // To know about 'cin' and 'cout'.
..
..
...
// Your code of interest.
..
..
// Put this stuff below at the end of your 'main' function.
char somevar; // Exists just to recieve input.
cout << "Press a key when ready"; // To let you know it's waiting.
cin >> somevar; // The pause will come while 'cin' waits.
...
// The end of your program, ie. 'main'.

Similiarly useful if you want a pause at other times too...
 
M

Mike Hewson

Mike said:
Unless your IDE doesn't do this ( it might but you may not have
found that yet ), then something like this:

#include <iostream> // To know about 'cin' and 'cout'.
..
..
...
// Your code of interest.
..
..
// Put this stuff below at the end of your 'main' function.
char somevar; // Exists just to recieve input.
cout << "Press a key when ready"; // To let you know it's waiting.
cin >> somevar; // The pause will come while 'cin' waits.
...
// The end of your program, ie. 'main'.

Similiarly useful if you want a pause at other times too...

Uh, yeah I know .... std::cin and std:cout or using's.....
( blush )
 
M

Mike Wahler

Mike Hewson said:
Uh, yeah I know .... std::cin and std:cout or using's.....
( blush )

I'm writing a new script for Monty Python. One scene begins:

"What.... is your namespace?"

-Mike
 
M

Mike Hewson

Mike said:
I'm writing a new script for Monty Python. One scene begins:

"What.... is your namespace?"

:) :) :)

Those guys even have their very own adjective - "Pythonesque"

( Gee I wish I had one of those )
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,298
Messages
2,571,540
Members
48,276
Latest member
Kaylee93L8

Latest Threads

Top