Problem Reading Paragraph into String
Nov 29, 2013 at 5:57am UTC
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
Nov 29, 2013 at 9:23am UTC
Nov 29, 2013 at 6:25pm UTC
That fixed it. Thanks!
Topic archived. No new replies allowed.