Do i need C to learn C++?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2006
Posts: 254
Reputation: jan1024188 is an unknown quantity at this point 
Solved Threads: 2
jan1024188's Avatar
jan1024188 jan1024188 is offline Offline
Posting Whiz in Training

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

 
1
  #11
Dec 30th, 2006
also you can get free c++ videotutorials here
http://seangreasley.com/
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 22
Reputation: WoBinator is an unknown quantity at this point 
Solved Threads: 0
WoBinator's Avatar
WoBinator WoBinator is offline Offline
Newbie Poster

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

 
0
  #12
Dec 30th, 2006
Originally Posted by jan1024188 View Post
also you can get free c++ videotutorials here
http://seangreasley.com/

awwww sweet as! thnx man!
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 44
Reputation: Boldgamer is an unknown quantity at this point 
Solved Threads: 2
Boldgamer's Avatar
Boldgamer Boldgamer is offline Offline
Light Poster

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

 
0
  #13
Dec 30th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,619
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 468
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

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

 
0
  #14
Dec 30th, 2006
Originally Posted by WoBinator View Post
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.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 488
Reputation: Bench has a spectacular aura about Bench has a spectacular aura about Bench has a spectacular aura about 
Solved Threads: 49
Bench's Avatar
Bench Bench is offline Offline
Posting Pro in Training

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

 
0
  #15
Dec 30th, 2006
For a standard, safe way of getting the program to pause, you could use a function like this
  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.
¿umop apisdn upside down?
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 254
Reputation: jan1024188 is an unknown quantity at this point 
Solved Threads: 2
jan1024188's Avatar
jan1024188 jan1024188 is offline Offline
Posting Whiz in Training

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

 
0
  #16
Dec 30th, 2006
Originally Posted by Bench View Post
For a standard, safe way of getting the program to pause, you could use a function like this
  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

  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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,619
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 468
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

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

 
0
  #17
Dec 30th, 2006
@ 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:
  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 .
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

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

 
0
  #18
Dec 30th, 2006
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.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

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

 
0
  #19
Dec 30th, 2006
  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.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,619
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 468
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

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

 
0
  #20
Dec 30th, 2006
Originally Posted by iamthwee View Post
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.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC