Problem Reading Paragraph into String

Hi,

I'm trying to read a paragraph into a string after reading a number into an int. I'm using Xcode.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <string>
using namespace std;

int main()
{
    int num;
    string temp, paragraph;
    
    cout << "Input number" << endl;
    cin >> num;
    
    cout << "Input paragraph" << endl;
    cin.ignore('\n');
    do {
        getline(cin, temp);
        paragraph += (temp + "\n");
    } while (temp.length() > 0);
    
    cout << paragraph << endl << num;
}


When I input the paragraph, it skips the first nine characters (including newlines) and outputs the rest (the int prints out just fine). Any idea what's going on here?

Thanks for the help!

Kyle
you use ignore the wrong way, see:

http://www.cplusplus.com/reference/istream/istream/ignore/

The first parameter is the number of characters to ignore. The second paramter is the delimiter to stop at

'\n' -> resolves to 10, see:

http://en.wikipedia.org/wiki/ASCII
That fixed it. Thanks!
Topic archived. No new replies allowed.