1. #1

    Registered
    04/11/03
    Location
    Wervik
    Posts
    1,901
    iTrader
    35 (100%)
    Mentioned
    0 Post(s)
    Reputation
    1/14

    C++ getline funny behaviour

    Hoi,

    wou ik eens c++ oefenen, met het begin en kom ik al meteen iets vreemd tegen.

    Code:
    #include <string>
    #include <iostream>
    
    int main() {
        using namespace std;
        const int THISYEAR = 2012;
        string yourName;
        string gameName;
        int height;
        int birthYear;
    
    
        cout << " What is your name? "  << flush;
        //cin >> yourName;
        getline(cin, yourName);
    
        cout << "What year were you born? " ;
        cin >> birthYear;
    
        cout << "How tall are you (cm)? ";
        cin >> height;
    
        cout << "What is the name of your favorite game? " << flush;
        getline(cin, gameName);
    
        cout << "Your name is " << yourName
                << " and you are approximately "
                << (THISYEAR - birthYear)
                << " years old. " << endl << "You are " << height
                << "cm's tall and your favourite game is " << gameName << endl;
    }
    Ik krijg nooit de kans om m'n favoriete game in te geven, waarom niet? met cin >> gameame lukt het wel maar dan kan ik geen gespacieerde namen ingeven als je begrijpt wat ik bedoel.

    Kan iemand even checken?
    no votes  

  2. #2
    forloRn_'s Avatar
    Registered
    23/11/03
    Location
    Landeurp
    Posts
    1,791
    iTrader
    0
    Mentioned
    0 Post(s)
    Reputation
    10/17
    Zelfde probleem hier, maar ik heb de oplossing al gevonden: Tips and Tricks for Using C++ I/O (input/output)
    no votes  

  3. #3

    Registered
    04/11/03
    Location
    Wervik
    Posts
    1,901
    iTrader
    35 (100%)
    Mentioned
    0 Post(s)
    Reputation
    1/14
    bedankt!
    no votes  

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Log in

Log in