473,400 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,400 software developers and data experts.

Console Programming in C++

I am taking a class in C++. We are creating console
applications using Visual C++.NET 2002. The assignment is
to create a "mailing label" using information coded into
the program. My code looks like this:

#include <iostream>

using std::cout;
using std::endl;

void main(void)
{
cout<<"Joe Schmoe"<<endl;
cout<<"5991 Crestview Ave"<<endl;
cout<<"Fairfield, OH 45014"
}//end of main

When I run this program the console appears and then
disappears before I can see the output. My instructor
suggested adding a getch() at the end of main, but the
compiler notes that there is an undeclared identifier.
How can I correct this problem with getch? Is there
another way to keep the console open until the user hits
a key?

Thank you,

Robert
Nov 16 '05 #1
4 6416
#include <conio.h> for getch()

--
Regards,
Nish [VC++ MVP]

"Robert Shull" <ro****@scoutingonline.org> wrote in message
news:10****************************@phx.gbl...
I am taking a class in C++. We are creating console
applications using Visual C++.NET 2002. The assignment is
to create a "mailing label" using information coded into
the program. My code looks like this:

#include <iostream>

using std::cout;
using std::endl;

void main(void)
{
cout<<"Joe Schmoe"<<endl;
cout<<"5991 Crestview Ave"<<endl;
cout<<"Fairfield, OH 45014"
}//end of main

When I run this program the console appears and then
disappears before I can see the output. My instructor
suggested adding a getch() at the end of main, but the
compiler notes that there is an undeclared identifier.
How can I correct this problem with getch? Is there
another way to keep the console open until the user hits
a key?

Thank you,

Robert

Nov 16 '05 #2
"Robert Shull" <ro****@scoutingonline.org> wrote in message
news:10****************************@phx.gbl...
When I run this program the console appears and then
disappears before I can see the output. My instructor
suggested adding a getch() at the end of main, but the
compiler notes that there is an undeclared identifier.


If you would rather not have to add the extra lines to your program you can
run it at the command line. That is, first run CMD.EXE to get a process that
runs the command interpreter. Once there type the full path to your console
application. CMD.EXE will start your process pointing it to the existing
console window.

A tip from my friend Doug H. is to add the command prompt as an external
tool to the IDE from the menu: Tools->External Tools->Add. You can use a
title of 'Prompt', a command of 'c:\winnt\system32\cmd.exe' and an initial
directory of $(TargetDir). Then to run your program you can just type its
name with neither path nor extension.

Regards,
Will


Nov 16 '05 #3
Or just use Ctrl-F5 in which case VS.NET pauses the console and waits till
you press a key before closing it

--
Regards,
Nish [VC++ MVP]

"William DePalo [MVP VC++ ]" <wi***********@mvps.org> wrote in message
news:#b**************@TK2MSFTNGP10.phx.gbl...
"Robert Shull" <ro****@scoutingonline.org> wrote in message
news:10****************************@phx.gbl...
When I run this program the console appears and then
disappears before I can see the output. My instructor
suggested adding a getch() at the end of main, but the
compiler notes that there is an undeclared identifier.
If you would rather not have to add the extra lines to your program you

can run it at the command line. That is, first run CMD.EXE to get a process that runs the command interpreter. Once there type the full path to your console application. CMD.EXE will start your process pointing it to the existing
console window.

A tip from my friend Doug H. is to add the command prompt as an external
tool to the IDE from the menu: Tools->External Tools->Add. You can use a
title of 'Prompt', a command of 'c:\winnt\system32\cmd.exe' and an initial
directory of $(TargetDir). Then to run your program you can just type its
name with neither path nor extension.

Regards,
Will


Nov 16 '05 #4
Thanks for your help. This solved the problem.

The other solution I had encountered was to use:

system("pause");

Robert
Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Richard Shea | last post by:
Hi - I wondered if anyone had done this before and could provide some suggestions ? I'm interested in supplying extra functionality to a Win32 Console (cmd.exe) - full description below for those...
43
by: Dom | last post by:
can someone please help me display text in the console cout << "Testing"; in a different colour to the default one
4
by: porous | last post by:
hi i would like to develop applications for windows in c++ , but i dont want to do any gui .i just want the program to be in console mode . but i would like to access the widows api . can any...
2
by: Boba | last post by:
Hi, I'm programming a WinForm application. I would like to enter commands that will send output that will help me to locate bugs in the future. I know that there is a way to send output by...
2
by: Jerry chapman | last post by:
Several years ago I wrote a console program in Visual C++, which I am still using. In converting this program to C#, I have encountered the following problems: 1. I build my console display in...
10
by: ryan.andrus | last post by:
Hi, I need to make a command line application that I have written support an option that allows the user to use the /p:* switch to specify that they would like to type a password but have it...
3
by: Daniel Clark | last post by:
I have a Windows command line based application that only shuts down cleanly if it sees "CTRL-C" on the console. I need to automate the running of this application, but still allow the user sitting...
3
by: Alex | last post by:
Hello, I'm wroting a console utility in VB 2005, and I need the ability to pass parameters to the application when the program runs. For example, if my program is called testing.exe, I need to...
6
by: Shankar | last post by:
Hi, I am not able to print the Unicode character on the console. I tried with these API's 1) wprintf() displays ??????? 2) _cwprintf() displays
5
by: =?Utf-8?B?UGFvbG8=?= | last post by:
I'm learning C# via console apps (to avoid getting bogged down in Windows stuff). I'm wondering how the OO paradigm would work. Say I'm developing 'classic' menu-driven apps where a menu gives a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.