Problem with getline function.

Discussion in 'Mac Programming' started by gmcguinn, Feb 3, 2011.

  1. gmcguinn, Feb 3, 2011
    Last edited: Feb 3, 2011

    gmcguinn macrumors newbie

    gmcguinn

    Joined:
    Jan 20, 2011
    Location:
    Dublin, Ireland
    #1
    Code:
    [COLOR="Lime"]// ******************************************************* //
    //    Program to grasp the idea of the getline function                           //
    // ******************************************************  //[/COLOR]
    
    
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main ()
    {
    	int age; 
        string zipcode,name,address;
    	
        cout << "Please enter your name\n";
        getline(cin,name);
        cout << "Please enter your age\n";
        cin >> age;
        cout << "Please enter your zipcode\n";
        cin >> zipcode;
        cout << "Please enter your address\n";
        getline(cin,address);
        
        
        cout << "Your details : "; 
        cout << name;
        cout << age << " years old."; 
        cout << address;  
        cout << zipcode "\n";
        
        return 0;
    }
    This is the error I get when run in terminal

    address.cpp: In function ‘int main()’:
    address.cpp:28: error: expected `;' before string constant (line 27 is cout << address;)
    make: *** [address] Error 1


    Cheers
     
  2. jazzbo macrumors member

    Joined:
    Oct 11, 2008
    Location:
    Bangor, ME
    #2
    So the error message says the problem is in line 28 -- and you've identified line 28 (since you know which one is line 27.) Does anything look wrong on that line?
     
  3. subsonix macrumors 68040

    Joined:
    Feb 2, 2008
    #3
    You need to chain the cout operators.
     
  4. gmcguinn thread starter macrumors newbie

    gmcguinn

    Joined:
    Jan 20, 2011
    Location:
    Dublin, Ireland
    #4
    Ahh my mistake! Thanks
     
  5. gmcguinn thread starter macrumors newbie

    gmcguinn

    Joined:
    Jan 20, 2011
    Location:
    Dublin, Ireland

Share This Page