   string input. ... please help
  Ok, here's a snippet of code:void createCustomer(){string firstName = " ";string middleName = " ";string lastName = " ";string street1 = " ";string street2 = " ";string city = " ";string state = " ";string zip = " ";string emailAddress = " ";char create = 'n';cout << endl;cout << "*** Create New Customer ***" << endl;cout << endl;cout << "First Name: ";cin >> firstName;cout << "Middle Name: ";cin >> middleName;cout << "Last Name: ";cin >> lastName;cout << "Street Address (line 1): ";getline(cin, street1);cout << "Street Address (line 2): ";getline(cin, street2);cout << "City: ";cin >> city;cout << "State: ";cin >> state;cout << "Zip: ";cin >> zip;cout << "Email Address: ";cin >> emailAddress;//show summary before creatingcout << endl << endl;cout << "The following customer will be created" << endl;cout << "======================================" << endl;cout << lastName << ", " << firstName << " " << middleName << endl;cout << street1 << endl;cout << street2 << endl;cout << city << ", " << state << " " << zip << endl;cout << emailAddress << endl;cout << "======================================" << endl;cout << "Are you sure you wish to create this customer (Y/N): ";cin >> create;if ((create == 'y') || (create == 'Y')){// create customer}else{cout << "Customer not created!" << endl;}}When I run my program and get stepping through this snippet of code, the input for the address lines do not work. It's kind of hard to describe the problem since I've tried so many things to get it working and ended up with 1000 different errors and I can't exactly remember which error goes with which code anymore. But here are a few of the problems I get (remember, these are from trying different ways of getting the data):1. sometimes after I enter line1 I get the following output on the next line"Street Address (line 2): City: State:" and then it'll wait there for input.2. sometimes it'll read address line 1 but when I do line two it fails. after I enter the text for line two and press enter it gives me another blank line. i then have to hit enter again to get to the city3. sometime it actually appears to work when i enter text but when the preview of the data shows what was entered I'm missing line 2.I've tried using cin.ignore(100, '\n') before the address line inputs.. i tried it after. .i tried it before and after. i tried it on every line where there's input.I've tried using cin.peek() and a while loop to get the char to see if it's a space or whatever (after reading the initial input).I've tried using getline(cin, variable, '\n')Umm.. bunch of other stuff.. Right now I'm so frustrated with this I can't even think. If this wasn't required for school I would just say screw it and move on to something that doesn't make me want to punch the computer. :)So please.. please please please... if anyone can help please do. Thanks in advance   
  Moving to For Beginners.Formatted input is whitespace delimited. If you type "123 S Foobar St" when asked for line one of the address, the stream will give you "123" and stop. The next read will produce "S" and then "Foobar" and so on, until the stream is finally empty. std::getline() is probably useful, just be very aware of the newline-discard policies of it and the formatted operations; otherwise you can get into more trouble mixing things up. Read your textbook.I'm going to stop short of telling you exactly what's wrong since this is for school work.   ;  sorry for posting in the wrong forum. I thought about the beginners forum but it said "new to game development" and this is not related to a game so I posted in the general section instead.Can anyone else offer more detailed assistance? Nothing against the response from jpetrie and I appreciate the concern about it being school work but I wouldn't be asking on here if I could have found the answer in my textbooks or even somewhere else online. Everything I can find says getline(cin, variable); is all I need. And if I'm just reading one line of text that appears to work fine. It's only when I get into reading numerous lines of text like this where it starts to fail. I've looked at probably 30 - 40 web sites today from beginners tutorials to advanced topics and they all pretty much say the same thing (although there was one that said to use cin.ignore(100, '\n') before the getline; i tried that btw and it did not work). At this point I really need either a direct "here's the problem" answer or a link to a site that contains the answer. I would be very very appreciative of a "here's the problem" answer with a "here's WHY it was a problem" description so that I know why it's failing and / or what I'm neglecting. I don't mind doing further research if all someone can provide is a link to a web site. My concern is that every site I'm finding on my own says the same thing (and that same thing does not work). And if you are curious as to what sites I've looked at just do a google search for "c++ read string with spaces".. "c++ string.getline()".. "c++ cin strings".. I've looked at every site on the first two pages of all of those queries with no luck.Thanks again!;  Ok, FINALLY found something that does work. But I don't know why it works.void createCustomer(){string firstName = " ";string middleName = " ";string lastName = " ";string street1 = " ";string street2 = " ";string city = " ";string state = " ";string zip = " ";string emailAddress = " ";char create = 'n';cout << endl;cout << "*** Create New Customer ***" << endl;cout << endl;cout << "First Name: ";cin >> firstName;cin.get();cout << "Middle Name: ";cin >> middleName;cin.get();cout << "Last Name: ";cin >> lastName;cin.get();cout << "Street Address (line 1): ";getline(cin, street1);cout << "Street Address (line 2): ";getline(cin, street2);cout << "City: ";cin >> city;cin.get();cout << "State: ";cin >> state;cin.get();cout << "Zip: ";cin >> zip;cin.get();cout << "Email Address: ";cin >> emailAddress;cin.get();//show summary before creatingcout << endl << endl;cout << "The following customer will be created" << endl;cout << "======================================" << endl;cout << lastName << ", " << firstName << " " << middleName << endl;cout << street1 << endl;cout << street2 << endl;cout << city << ", " << state << " " << zip << endl;cout << emailAddress << endl;cout << "======================================" << endl;cout << "Are you sure you wish to create this customer (Y/N): ";cin >> create;if ((create == 'y') || (create == 'Y')){// create customer}else{cout << "Customer not created!" << endl;}}why does adding the cin.get(); after each input make this work? What's it doing that I'm not aware of? And is this a 'real' solution or just some cheap work around?   ;Quote:Original post by furin591why does adding the cin.get(); after each input make this work? What's it doing that I'm not aware of? And is this a 'real' solution or just some cheap work around?It is not a real solution.Quote:Original post by jpetriestd::getline() is probably useful, just be very aware of the newline-discard policies of it and the formatted operations; otherwise you can get into more trouble mixing things up. Read your textbook.I'm going to stop short of telling you exactly what's wrong since this is for school work.Input operations, conceptually, read from a buffer. Anything that's left over from previous read is still there when the next read is attempted, regardless of what's happened in the meantime (unless those events include an explicit clearing of the buffer).The formatted operations will only read the word the user types. The user types, each time, a word followed by a newline. The newline is not read.When the getline call occurs, the newline is at the front of the buffer. An empty line (i.e. zero characters followed by a newline, i.e. a newline) is a valid line, so that's what getline sees.cin.get() reads a single character from the stream. In the case of your code, that's the newline that you want to discard.IF the user was nice, and typed the appropriate number of words.As a test, try typing a full name (first, middle and last) when prompted for the first name. You will see that all three values get read in: the program responds by immediately writing the prompts for middle name, last name and street address (line 1).The simplest way around this is, when the input is supposed to come from std::cin, always read a line at a time with std::getline, and re-parse the lines of input (to check them for validity: e.g. enforce that a first name has only one word in it).   