Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

C++ Question


  • Please log in to reply
5 replies to this topic

#1 Guest_danbrownlow_*

Guest_danbrownlow_*

  • Guests
  • OFFLINE
  •  

Posted 03 September 2007 - 05:42 PM

Hey there, I am using Dev C++ and have a problem. I am learning to code from a book called Accelerated C++ and have been trying to write the programs, however, I can't see the program because of it terminating to fast. For example, when I type:

// a small c++ program
#include <iostream>

int main()
{
std::cout << "Hello!" << std::endl;
return 0;
}

I know this is because of the return 0 at the end, but what do I need to put there instead so I can actually see the outcome of the program?
Thanks in advance,
Dan

BC AdBot (Login to Remove)

 


#2 xx66stangxx

xx66stangxx

  • Members
  • 139 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:O.C.

Posted 04 September 2007 - 09:11 AM

try adding system("PAUSE");

// a small c++ program
#include <iostream>

int main()
{
std::cout << "Hello!" << std::endl;

system("PAUSE");

return 0;

}


I think that should do it.

#3 gaming freakz

gaming freakz

  • Members
  • 33 posts
  • OFFLINE
  •  
  • Location:India
  • Local time:08:05 AM

Posted 09 September 2007 - 12:50 AM

Also,you don't need to use "std::" before and after every cout statement.Just put the following line

"using namespace std;" after "#include <iostream>".

To get the output to stay on screen,use "cin.get();"

#include <iostream>
using namespace std;
int main()
{
 cout<<"Hello!"<<endl;
 cin.get();
 return 0;
 
}

Edited by gaming freakz, 09 September 2007 - 12:59 AM.

By the time you have read this.....you have wasted 3 seconds of your life.

#4 Mr Alpha

Mr Alpha

  • Members
  • 1,875 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Finland
  • Local time:09:35 PM

Posted 09 September 2007 - 04:46 AM

At least Visual Studio lets you open a program in a console window that doesn't close by using Debug > Start Without Debugging.
"Anyone who cannot form a community with others, or who does not need to because he is self-sufficient [...] is either a beast or a god." Aristotle
Intel Core 2 Quad | XFX 780i SLI | 8GB Corsair | Gigabyte GeForce 8800GTX | Auzentech X-Fi Prelude| Logitech G15 | Logitech MX Revolution | LG Flatron L2000C | Logitech Z-5500 Digital

#5 Vgamecoder

Vgamecoder

  • Members
  • 31 posts
  • OFFLINE
  •  
  • Local time:07:05 PM

Posted 23 September 2007 - 06:29 PM

strange how every one has to type in codes like that this type of code works perfectly for me.

#include <iostream>

int main()
{
cout << "HI!";

cin.get();
}
Please Help Me With These Problems
-------------------------------------------
How Do I Add Images To A C++ Program

#6 monkpart9

monkpart9

  • Members
  • 256 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:New York
  • Local time:11:05 AM

Posted 24 October 2007 - 09:39 PM

Maybe you forgot "stdafx.h" ?
If you do things right, then people won't know if you've done anything at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users