Can't replicate. I don't see how you are getting an extraneous newline as the first character in the string unless that's the first thing you enter as your string.
It is strange that you would use a period as the terminating character in your getline call. Normally if you are reading a line you use the newline as a terminator.
What EXACTLY is the input you are entering?
Post a complete program with a main and all includes that we can run.
the assignment is that the user is supposed to enter their first name, age, and title in life regardless if it's the input is in the same line or in different lines (that's why the terminator is a period).
so let's say I enter the following in one line:
MyName 21 MyTitle
above input should have the same output if broken down in different lines
My Name
21 MyTitle
Which as I mentioned above should look like the following
You have entered: enteredName enteredAge enteredTitle
Name: enteredName
Age: enteredAge
Title: enteredTitle
UPDATE:
Here's the weirdest thing: when I run the codes by itself and apart from the rest of the program, it runs okay and without the extraneous newline... not sure if the error is in the other parts of the program...
UPDATE:
Here's the weirdest thing: when I run the codes by itself and apart from the rest of the program, it runs okay and without the extraneous newline... not sure if the error is in the other parts of the program...
I am not sure either because you did of include the rest of the program. Errors are notorious for starting in places you do not expect.
Here are two possibilities that should work better:
This works for entering everything on one line and takes into account that name may have a space in it. The std::ws will eat any white space at the beginning. So as the prompt you can enter "name, age, title" or "name,age,title" and either would work.
Another possibility is to enter each variable seperately:
Hi Andy!
thanks for your input!!!
My friend reminded me about the cin.ignore(), and it worked just okay.
is that the same as the std::ws you mentioned?
No. "std::cin.ignore()" and "std::ws" may appear to work the same. but they are completely different.
std::cin.ignore(1000, '\n'); works on the input buffer and will ignore or remove 1000 characters from the input buffer or until it finds a "\n" whichever comes first.
std::cin >> std::ws >> aVariable; works in the input stream after you press Enter and will ignore any leading white space before you reach something that can be put in a variable be it a letter, punctuation or a number. I found http://www.cplusplus.com/reference/cctype/isspace/ which has a nice table to show what is considered a white space. And http://www.cplusplus.com/reference/cctype/isspace/ that covers "std::cin >>std::ws" although the example code may not be the best.