Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 12-02-2005, 10:41 PM   #11
Daemon Poster
 
george's Avatar
 
Join Date: Mar 2005
Posts: 553
Send a message via MSN to george Send a message via Yahoo to george
Default Re: C++ not working properly

the #include <stdio.h> is used more in c, c++ uses the #include <iostream>
__________________

george is offline   Reply With Quote
Old 12-27-2005, 05:50 AM   #12
In Runtime
 
Logan's Avatar
 
Join Date: Dec 2005
Posts: 265
Send a message via AIM to Logan Send a message via MSN to Logan
Default Re: C++ not working properly

add this:

cin.ignore(cin.rdbuf()->in_avail() + 1);

before your return statement. then you hit enter.
__________________

Logan is offline   Reply With Quote
Old 01-02-2006, 02:47 PM   #13
Beta Member
 
Join Date: Jan 2006
Posts: 1
Default Re: C++ not working properly

not really, just

cin.get();

would do.
Dngsm is offline   Reply With Quote
Old 01-02-2006, 04:30 PM   #14
Daemon Poster
 
RewtGuy's Avatar
 
Join Date: Dec 2004
Posts: 595
Send a message via AIM to RewtGuy
Default Re: C++ not working properly

or you can use system ("pause"); with the cstdlib.

Code:
#include <iostream>
#include <cstdlib>

using namespace std;

int main ()
{
cout << "Hello world" << endl;
/* If you were to use stdio it'd be: */
/* printf ("Hello World\n"); */
system ("pause");
return 0;
}
It's not good to use a function such as cin or cin.get to "pause" the program. Think if you had multiple source files that you included, pausing like that in one of your other sources could cause our program to hang. Another reason is people could write exploits and use buffer overflow attacks on your computer.

Another solution would be to open up your terminal, by typing "command" in start, run. Then finding the location of your executable. Then typing in the location for example it could be in C:\DOCUME~1\USER\DESKTOP\program.exe This way your program won't just flicker by anyway and you don't have to use bad programming practices.
__________________
Windows: A thirty-two bit extension and GUI shell to a sixteen bit patch to an eight bit operating system originally coded for a four bit microprocessor and sold by a two-bit company that can't stand one bit of competition.
RewtGuy is offline   Reply With Quote
Old 01-12-2006, 10:33 PM   #15
C--
Solid State Member
 
C--'s Avatar
 
Join Date: Jan 2006
Posts: 8
Default Re: C++ not working properly

Um...are you sure you're clicking "start without debugging?" If you select "start debugging" in your IDE (assuming you are using Microsoft Visual C++) the program will test run and will quit automatically after all the commands have been executed. "Start Without Debugging" displays "Press any key..." in the console after the program is done executing. At least that's the problem I had when I first taught myself C++.
__________________

C-- is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 09:52 PM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0