Hi. Writing a program that reads multiple strings into a vector, displays them, then does some other stuff to them. The problem is that the first character of the string won't show up. (following excerpt is not complete program)
Well the first time you get something into the i variable you are not saving it into the vector.
1 2 3 4 5 6 7 8
cout << "Enter a string (ending with '.'): " << endl;
cin >> i; //**************this entry is not being saved
while (i != ".")
{
cin >> i;
v.push_back(i);
}
}
EDIT:
I might as well add that the firs t cin>> i is redundant anyway - because the default
constructor for string creates an empty string which wil not be equal to . so the loop will run - OR
you could create the string with some string value that is not equal to .
So - this will do the job.
1 2 3 4 5 6 7 8 9
string i; //the default constructor creates an empty string
cout << "Enter a string (ending with '.'): " << endl;
//cin >> i; //get rid of this line - it is redundant.
while (i != ".")
{
cin >> i;
v.push_back(i);
}
}