943,865 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 10582
  • C++ RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Dec 30th, 2006
1

Re: Do i need C to learn C++?

also you can get free c++ videotutorials here
http://seangreasley.com/
Reputation Points: 27
Solved Threads: 2
Posting Whiz in Training
jan1024188 is offline Offline
254 posts
since Aug 2006
Dec 30th, 2006
0

Re: Do i need C to learn C++?

Click to Expand / Collapse  Quote originally posted by jan1024188 ...
also you can get free c++ videotutorials here
http://seangreasley.com/

awwww sweet as! thnx man!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
WoBinator is offline Offline
22 posts
since Dec 2006
Dec 30th, 2006
0

Re: Do i need C to learn C++?

Quote ...
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?
Add

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.
Reputation Points: 11
Solved Threads: 2
Light Poster
Boldgamer is offline Offline
44 posts
since Dec 2006
Dec 30th, 2006
0

Re: Do i need C to learn C++?

Click to Expand / Collapse  Quote originally posted by WoBinator ...
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 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.
Super Moderator
Featured Poster
Reputation Points: 3233
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,871 posts
since Jun 2006
Dec 30th, 2006
0

Re: Do i need C to learn C++?

For a standard, safe way of getting the program to pause, you could use a function like this
CPP Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <limits>
  3.  
  4. void stop()
  5. {
  6. std::cin.ignore( std::numeric_limits<std::streamsize>::max() , '\n');
  7. std::cin.get();
  8. }
  9.  
  10. int main()
  11. {
  12. stop();
  13. }
Last edited by Bench; Dec 30th, 2006 at 1:32 pm.
Reputation Points: 307
Solved Threads: 62
Posting Pro
Bench is offline Offline
565 posts
since Feb 2006
Dec 30th, 2006
0

Re: Do i need C to learn C++?

Click to Expand / Collapse  Quote originally posted by Bench ...
For a standard, safe way of getting the program to pause, you could use a function like this
CPP Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <limits>
  3.  
  4. void stop()
  5. {
  6. std::cin.ignore( std::numeric_limits<std::streamsize>::max() , '\n');
  7. std::cin.get();
  8. }
  9.  
  10. int main()
  11. {
  12. stop();
  13. }
wow but this doesnt make sense

why dont you just type

C++ Syntax (Toggle Plain Text)
  1. #include <iostrem.h>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. void main()
  7. {
  8. cout << "\n" ;
  9. cin.get();
  10. return(0);
  11. }
Last edited by jan1024188; Dec 30th, 2006 at 1:43 pm.
Reputation Points: 27
Solved Threads: 2
Posting Whiz in Training
jan1024188 is offline Offline
254 posts
since Aug 2006
Dec 30th, 2006
0

Re: Do i need C to learn C++?

@ 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:
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <limits>
  3.  
  4. void stop( )
  5. {
  6. using namespace std ;
  7.  
  8. cin.clear( ) ;
  9. cin.ignore( numeric_limits<streamsize>::max(), '\n' ) ;
  10. cin.get( ) ;
  11. }

@ 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 .
Super Moderator
Featured Poster
Reputation Points: 3233
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,871 posts
since Jun 2006
Dec 30th, 2006
0

Re: Do i need C to learn C++?

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.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Dec 30th, 2006
0

Re: Do i need C to learn C++?

C++ Syntax (Toggle Plain Text)
  1. #include <iostrem.h>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. void main()
  7. {
  8. cout << "\n" ;
  9. cin.get();
  10. return(0);
  11. }

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.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Dec 30th, 2006
0

Re: Do i need C to learn C++?

Click to Expand / Collapse  Quote originally posted by iamthwee ...
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.
Super Moderator
Featured Poster
Reputation Points: 3233
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,871 posts
since Jun 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Using Command Line Arguments?
Next Thread in C++ Forum Timeline: Need help with my code





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC