943,534 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 22375
  • C++ RSS
Mar 18th, 2006
0

Projects in C++

Expand Post »
He friends,
I would like to have some guidance over projects to take up in C++?
I would like to take up a challenging project . Also I have changed my compiler from turbo C++ to Dev C++ but i cannot figure out how the output can be seen ie the output window. Also how do we step into or step over .
Thanks for your help,
comwizz.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
comwizz is offline Offline
39 posts
since Nov 2005
Mar 18th, 2006
0

Re: Projects in C++

I don't want to step on any C++ toes, but there is a "Projects for Beginners" thread in the Python forum. Much of it is applicable to C++ programmers too. Take a look at:
http://www.daniweb.com/techtalkforums/thread32007.html

For Dev-C++ users there is a little handholding advice in this code snippet:
http://www.daniweb.com/code/snippet82.html

Also for console programs here are ways to make the console output wait for a key stroke, so you can read the output:
C++ Syntax (Toggle Plain Text)
  1. // wait for key press at end of console program
  2.  
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. void wait();
  8.  
  9. int main()
  10. {
  11. // Your code here
  12.  
  13. // C++
  14. cin.sync(); // purge any \n
  15. cin.get(); // console wait
  16.  
  17. // or
  18. // clear the stream, purge any \n
  19. while (cin.get() != '\n')
  20. ;
  21. cin.get(); // wait
  22.  
  23. // or
  24. // more complete
  25. while (std::cin.get(ch) && ch != '\n')
  26. ;
  27. cin.get(); // wait
  28.  
  29. // or
  30. cin.ignore ( 1024, '\n' );
  31. cin.get(); // wait
  32.  
  33. // or
  34. cin.get(); // trap loose \n
  35. cin.get(); // wait
  36.  
  37. wait(); // write your own, for C++
  38.  
  39. // system("PAUSE"); // wait, not portable
  40.  
  41. // C
  42. // clear the stream
  43. while ((ch = getchar()) != '\n' && ch != EOF);
  44. getchar(); // for C, same caveat as cin.get()
  45.  
  46. return 0;
  47. }
  48.  
  49. // portable, need to declare prototype unless
  50. // function precedes call
  51. void wait()
  52. {
  53. cout << "Press any key to continue ...";
  54. string z;
  55. getline(cin,z);
  56. }
I am a little skittish posting in the C++ forum, since I have been kicked out of here unceremoniously in the past.
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Mar 18th, 2006
0

Re: Projects in C++

>cin.sync(); // purge any \n
This non-portable. From a standard perspective, it's also nonsensical for sync to discard the contents of the buffer. I've discussed it at length here.
C++ Syntax (Toggle Plain Text)
  1. cin.ignore ( 1024, '\n' );
  2. cin.get(); // wait
Magic numbers should be avoided:
C++ Syntax (Toggle Plain Text)
  1. #include <ios>
  2. #include <limits>
  3.  
  4. cin.ignore ( numeric_limits<streamsize>::max(), '\n' );
  5. cin.get(); // Wait
C++ Syntax (Toggle Plain Text)
  1. cin.get(); // trap loose \n
  2. cin.get(); // wait
This only works if the only thing left in the stream is a newline.
C++ Syntax (Toggle Plain Text)
  1. cout << "Press any key to continue ...";
  2. string z;
  3. getline(cin,z);
That's seriously overkill, and the prompt is misleading because getline is line oriented. You can hit any key, but unless that key is Enter, nothing will happen.

>I am a little skittish posting in the C++ forum, since I have been kicked out of here unceremoniously in the past.
I don't recall you being "kicked out". Can you link to the offending thread?
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004

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: save ARRay elements to a file
Next Thread in C++ Forum Timeline: Borland C++5.5 compiler - shortcut ?





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


Follow us on Twitter


© 2011 DaniWeb® LLC