working with strings / input char validation

I just found a function that one of my former professors made for us to use in class and I did not understand a line and what it does. I haven't had this professor for several semesters so I can't ask him. What does line 14 do?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
void getChar(char& charInput)
{
	string			input;
	string::size_type 	len;

	while (true)
	{
		getline(cin, input);
		len = input.length();
		if (len != 1)
			cout << "Please enter a valid character as your response ==> ";
		else
		{
			charInput = input[0];
			return;
		}
	}
	return;
}
Last edited on
In line 14 variable charInput is assigned the first character of object input of type std::string.
This might help: http://www.cplusplus.com/reference/string/string/operator%5B%5D/

The function seems rather strange as a whole, I'm not sure what the use would be.
Topic archived. No new replies allowed.