cin issue

I'm having trouble with cin, in this code it doesn't allow the user to input the name

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
void display2(char char1, int num)
{
    for(int count = 1; count <= num; count++)
    {
        cout << char1;
    }
    cout << endl;
}

int main()
{
    char char1, char2; int num, num2; string name, address, city;
    cout << "Enter the character to be used in the heading:" << endl;
    cin >> char1;
    cout << "Enter the number of times the header character wil be used:" << endl;
    cin >> num;
    cout << "Enter full name:" << endl;
    getline(cin, name);
    cout << "Enter street address:" << endl;
    getline(cin, address);
    cout << "Enter city, state, zip code:" << endl;
    getline(cin, city);
    cout << "Enter character to be used in footer" << endl;
    cin >> char2;
    cout << "Enter the number of times the footer character will be used:" << endl;
    cin >> num2;
    cout << endl;
    display2(char1, num);
    cout << name << endl;
    cout << address << endl;
    cout << city << endl;
    char1 = char2;
    num = num2;
    display2(char1, num);
    return 0;
}
Line 18:
1
2
3
// getline(cin, name);
getline( cin >> ws, name); // extract and discard the new line remaining in the 
                           // input buffer before trying to read the name 


More information: http://www.cplusplus.com/forum/general/69685/#msg372532
Topic archived. No new replies allowed.