Can't get getline() to work

When I put breakpoints to watch it, it skips right over the line where it should read getline(cin, sentence). why is it doing this and how can I fix it? It goes straight to the line that reads "PASSWORD IS INVALID".

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
  string setlevel2()
{
	string sentence;
	bool one = false, two = false;
	cout << "Second level of security program" << endl;
	cout << "Enter a sentence you would like to use ";
	cout << "(it must contain more than one word and end in a '.')" << endl;
	cin.clear();
	//cin >> sentence;
	getline(cin, sentence);
	for (unsigned int x = 0; x <= sentence.length(); x++)
	{
		if (sentence[x] == ' ')
		{
			one = true;
		}
		else if (sentence[x] == '.')
		{
			two = true;
		}
	}
	if (one == true && two == true)
	{
		cout << "PASSWORD IS VALID" << endl;
		return sentence;
	}
	else
	{
		cout << "PASSWORD IS INVALID" << endl;
		system("pause");
		exit(0);
	}
}
When I tried using cin>> it worked but I need to read a full sentence. Not just one word.
Topic archived. No new replies allowed.