|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Member (9 bit)
Join Date: Apr 2004
Location: Woburn, MA
Posts: 402
|
C++ Question
I did not see any other forums with c++ as a possible subject so I am taking it here. I am just starting to learn the programming language. Now I am sure anyone even a little experienced with C++ knows about the "Hello World" program that almost everyone writes as a first practice code. I am using Dev C++ as a compiler just in case this helps. Now whenever I write the hello world program, it compiles and runs fine but it only flashes on the screen for a very breif second. Now I know there is a line of code you can insert at the bottom of your project to make the dos prompt type window stay open so you can read your project but I forgot what it is. Does anybody know what the line of code to make the dos window stay open so I can see what I've done?
|
|
|
|
|
|
#2 |
|
Forum Administrator
Staff
Premium Member
Join Date: May 2000
Location: Joplin MO
Posts: 37,786
|
Moved to.......
Web Development & Hosting Questions about HTML, CSS, Javascript, Java, MySQL, PHP, Perl, general programming, and Web Hosting. Want to know what others think of your site? Ask here.. |
|
|
|
|
|
#3 |
|
Member (9 bit)
Join Date: Feb 2005
Posts: 392
|
use "getchar()"
example: include< cstdio > include ... ..... do whatever output line ....... then in the end: getchar(); // equivalent to PAUSE in DOS ---------------------- the above line stop the program for as long as you wanted until you press a key on the keyboard.
__________________
words to live by: others don't know, I know. others know, I know more. others know more, I excel. one shouldnt read this far; above, is meant as an encouragement, translated from a Chinese Proverb. "He who angers you conquers you." : Elizabeth Kenny Last edited by alfie2; 01-02-2006 at 03:19 AM. |
|
|
|
|
|
#4 |
|
Member (7 bit)
Join Date: Dec 2005
Posts: 87
|
I written batch programs before that output directly to the console and to do this I just wrote PAUSE. Hope it helps.
On a personal note I found it easier to start with managed code like C#. Here is a link to some great tutorial videos: http://msdn.microsoft.com/vstudio/ex...g/default.aspx I just thought the managed code seemed similar, plus this is running on Microsoft .NET 2.0. I don't know if Dev C++ is the newest one. Also you can get C# Visual Express for free and it allows you to develop MS SQL Server applications completly free of charge. It's pretty cool. |
|
|
|
|
|
#5 |
|
Member (10 bit)
|
add the header: #include
add this line before your "return 0" : getch(); *edit: wait...sorry. dunno if this will work. i do C only. you can try it though* |
|
|
|
|
|
#6 |
|
Member (9 bit)
Join Date: Apr 2004
Location: Woburn, MA
Posts: 402
|
cool, thanks guys, the getchar(); worked like a dream, I haven't tried pause yet but I wil, thanks again
|
|
|
|
|
|
#7 |
|
Wx geek
Join Date: Aug 2005
Location: Indiana
Posts: 6,638
|
Also, try loading the program from the command prompt. That'll keep the text up there. What OS are you using?
__________________
"It is the way of man to make monsters and it is the nature of monsters to destroy their makers." |
|
|
|
|
|
#8 |
|
Member (9 bit)
Join Date: Apr 2004
Location: Woburn, MA
Posts: 402
|
Running XP Pro
|
|
|
|
|
|
#9 |
|
Wx geek
Join Date: Aug 2005
Location: Indiana
Posts: 6,638
|
You could start up the command prompt (Win Key + R), type in cmd and then you can navigate folders in the command prompt to the folder with the executable in. Use cd _folder name_/_sub folder_ and ../ to navigate up (Like C:/Documents and Settings to C:/). Then type in the name of the executable once your in the project folder.
|
|
|
|
|
|
#10 |
|
Member (9 bit)
Join Date: Feb 2005
Posts: 392
|
Hags , Blue60007:
I dont think, that will work with programs compiled using Windows-based compilers; it will work with DOS based compilers. because a Windows-based compiler will create a executable which will open a "child window" when you run/executed it. therefore same thing happens....window open prints output, then closes window. |
|
|
|
|
|
#11 |
|
Wx geek
Join Date: Aug 2005
Location: Indiana
Posts: 6,638
|
You sure? I've never used Dev C++ so I don't know how that works.
I'm using VS .NET 2003 and I can run programs as I described just fine. |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|