Thread: First Program

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    <In Learning Mode>
    Join Date
    Dec 2004
    Posts
    6
    thankyou so much for your replies, and thankyou SlyMaelstrom for re-writing the program, it now works just the way i wanted it to

    Please could you explain a bit more about why cin.ignore() was required and cin.get() didn't work because i dont understand where i had the newline character in the input stream or what it causes

    I would also like to know about how program code is read by the computer (program\source code flow) so that i can understand how to write code in the correct order because you were right about me not putting the "\n" character in the right place.
    Last edited by $watto; 11-20-2005 at 01:07 PM.

  2. #2
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by $watto
    t
    Please could you explain a bit more about why cin.ignore() was required and cin.get() didn't work because i dont understand where i had the newline character in the input stream or what it causes
    cin >> letter just pulls one character from cin. But you have to actually type a character and a newline to get anything from cin. The newline stays in the buffer. if you call cin.get() afterwards there is still that newline in the buffer and that will get returned. So it looks like it has no effect.
    SlyMaelstrom has put a cin.ignore() after the cin >> letter. this kind of empties the buffer so cin.get() will wait for some more input.
    Kurt

  3. #3
    Rabite SirCrono6's Avatar
    Join Date
    Nov 2003
    Location
    California, US
    Posts
    269
    Just a quick note:

    Code:
    convert = static_cast<int>( letter );
    is usually used with C++, whereas ( int )letter is a C-Style cast.

    - SirCrono6
    From C to shining C++!

    Great graphics, sounds, algorithms, AI, pathfinding, visual effects, cutscenes, etc., etc. do NOT make a good game.
    - Bubba

    IDE and Compiler - Code::Blocks with MinGW
    Operating System - Windows XP Professional x64 Edition

  4. #4
    !anExpert
    Join Date
    Mar 2005
    Location
    pa
    Posts
    155
    Quote Originally Posted by SirCrono6
    Just a quick note:

    Code:
    convert = static_cast<int>( letter );
    is usually used with C++, whereas ( int )letter is a C-Style cast.

    - SirCrono6
    It should be pointed out here that a cast is not needed in the case of chars and ints
    Code:
    int main()
    {
        char in='\0';
        int out=0;
        cin >> in;
        out=in;
        cout << out << endl;
        return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM