| | |
Do i need C to learn C++?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
awwww sweet as! thnx man!
•
•
•
•
omg...last question ^^
ive written and comiled the "hello world" thing using Dev-C++
when i run the exe, a dos-like window pops up for half sec and dissapears...wtf? ive read and reread over what i am meant to do...?!?!?! is that whats meant to hpn?
system("PAUSE");
in front of return 0;
Last edited by Boldgamer; Dec 30th, 2006 at 12:42 pm. Reason: Sorry. I quoted the wrong person.
•
•
•
•
ive written and comiled the "hello world" thing using Dev-C++
when i run the exe, a dos-like window pops up for half sec and dissapears...wtf? ive read and reread over what i am meant to do...?!?!?! is that whats meant to hpn?
To make the command window stay, make the program wait for some event (like accepting a key from the user) to see the expected output.
In C do getchar( ) at the end of the program.
In C++ do cin.get( ) at the end of the program.
Any other method used, is totally platform / compiler dependent and should be best avoided.
BTW even system( "pause" ) is a non-standard method which is best avoided.
I don't accept change; I don't deserve to live.
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
For a standard, safe way of getting the program to pause, you could use a function like this
CPP Syntax (Toggle Plain Text)
#include <iostream> #include <limits> void stop() { std::cin.ignore( std::numeric_limits<std::streamsize>::max() , '\n'); std::cin.get(); } int main() { stop(); }
Last edited by Bench; Dec 30th, 2006 at 1:32 pm.
¿umop apisdn upside down? •
•
•
•
For a standard, safe way of getting the program to pause, you could use a function like thisCPP Syntax (Toggle Plain Text)
#include <iostream> #include <limits> void stop() { std::cin.ignore( std::numeric_limits<std::streamsize>::max() , '\n'); std::cin.get(); } int main() { stop(); }
why dont you just type
C++ Syntax (Toggle Plain Text)
#include <iostrem.h> using namespace std; void main() { cout << "\n" ; cin.get(); return(0); }
Last edited by jan1024188; Dec 30th, 2006 at 1:43 pm.
@ Bench
Just to let you know that the functions cin.ignore( ) and cin.get( ) won't function as expected if the standard input stream is corrupted and its status bit not cleared. Your code is good and robust but to make it to adapt to stream corruptions, do something like:
@ jan1024188
There are some cases in which the simple statement getchar( ) or cin.get( ) won't work. Those being corrupted stream, or more than a single newline character hanging in the stream.
For simple cases the primitive statements work well, but if your program is a highly CUI (console user interface) dependent, you might want to have a robust function like mentioned above by me and Mr. Bench to handle fatalitites
.
Just to let you know that the functions cin.ignore( ) and cin.get( ) won't function as expected if the standard input stream is corrupted and its status bit not cleared. Your code is good and robust but to make it to adapt to stream corruptions, do something like:
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <limits> void stop( ) { using namespace std ; cin.clear( ) ; cin.ignore( numeric_limits<streamsize>::max(), '\n' ) ; cin.get( ) ; }
@ jan1024188
There are some cases in which the simple statement getchar( ) or cin.get( ) won't work. Those being corrupted stream, or more than a single newline character hanging in the stream.
For simple cases the primitive statements work well, but if your program is a highly CUI (console user interface) dependent, you might want to have a robust function like mentioned above by me and Mr. Bench to handle fatalitites
. I don't accept change; I don't deserve to live.
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
C++ Syntax (Toggle Plain Text)
#include <iostrem.h> using namespace std; void main() { cout << "\n" ; cin.get(); return(0); }
We've told you time and time again, don't use void main and don't use iostream.h.
But what do you do? Dearie me.
*Voted best profile in the world*
•
•
•
•
I wouldn't put 'using namespace std' within the scope of a function.
It is better to state it at the top - just under the headers.
Programs should be made avail of only that much functionality which concerns them hence declaring the namespace in the function was for the best.
I don't accept change; I don't deserve to live.
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
![]() |
Similar Threads
- Which language to learn? (Computer Science)
- how i can learn c++ (C++)
- How to learn graphical part of C++? (C++)
- what is the best book to learn SQL fast and quick (MS SQL)
- need to learn more just not sure where to start (Viruses, Spyware and other Nasties)
- Learn How to Spot a 16-Bit Application (Windows tips 'n' tweaks)
Other Threads in the C++ Forum
- Previous Thread: Using Command Line Arguments?
- Next Thread: Need help with my code
Views: 8488 | Replies: 49
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api array arrays based beginner binary bmp c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete deploy dll download dynamic dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib library lines linker list loop looping loops map math matrix memory newbie news number output pointer problem program programming project python random read recursion recursive reference return rpg search simple sort spoonfeeding string strings struct temperature template templates text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






