Subscript out of range

Okay so this is driving me freaking insane.

Testing this with input (no integers) : works
Testing this by failing the condition (using a space) and then inputing no integers : works

However, if for example I test the condition by just pressing enter, and then entering an input with no integers, I get the error "subscript out of range"


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
	int uLength;
	int ex = 1;
	int check = 0;
	char nCheck = '\n';
	string nameFile = "";
	string userFile = "";

	cout << "Enter your name please.\n";
	getline(cin, nameFile);

	uLength = nameFile.length();
	while (ex == 1)
	{
		while (uLength > check || uLength == 0)
		{
			if (isdigit(nameFile[check]) || nameFile[check] == ' ' || nameFile.empty())
			{
				cout << "That is not a valid input, please try again: ";
				cin.clear();
				getline(cin, nameFile);
				check = 0; //reset counter
			}
			else
			{
				check++;
			}
		ex = 0;

	}
}



Last edited on
You don't update the value of uLength when nameFile changes on line 20.
Topic archived. No new replies allowed.