You do not need to learn c before c++.
I found c++ so easy to learn, it should be like a walk in the park.
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
>it is much easyer to understand c++ if you know c....
Perhaps, but some people still think c++ is just c with classes.
My advice would be to learn c++ on its own away from the distractions of c.
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
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?
The program is doing exactly what it is supposed to do, the only thing being the command window closes after displaying the output.
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 dogetchar( ) 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.
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
@ 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:
#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 ;).
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
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.
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
#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.
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
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.
Declarations are best made in the proximity where they are required to be used. Limiting the scope of the namespace declaration namespace collisions can be avoided.
Programs should be made avail of only that much functionality which concerns them hence declaring the namespace in the function was for the best.
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734