Quick question!

Compiling the following code:
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
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <string>

using namespace std;

int countVowels(string aLetter, string aString);

int main()
{
	string enteredString;
	cout << "Please enter a string: ";
	getline(cin, enteredString);

	int a = countVowels("a", enteredString);
	int e = countVowels("e", enteredString);
	int i = countVowels("i", enteredString);
	int o = countVowels("o", enteredString);
	int u = countVowels("u", enteredString);

	cout << "The letter a appears " << a << " time/s." << endl;
	cout << "The letter e appears " << e << " time/s." << endl;
	cout << "The letter i appears " << i << " time/s." << endl;
	cout << "The letter o appears " << o << " time/s." << endl;
	cout << "The letter u appears " << u << " time/s." << endl;

	return 0;
}

int countVowels(string aLetter, string aString)
{
	int count = 0;
	string extractedLetter;

	for (int i = 0; i < aString.length(); i++)
	{
		extractedLetter = aString.at(i);
		if (extractedLetter == aLetter)
			count++;
	}

	return count;
}

is giving me the following warning:
(34) : warning C4018: '<' : signed/unsigned mismatch

Why? What does it mean? Thanks!
Last edited on
closed account (z05DSL3A)
The return value for string.length() in an unsigned int and i is a signed int. As the value of an unsigned int can exceed the top range of a signed int, the compiler issues a warning.

Try:
for (unsigned int i = 0; i < aString.length(); i++)
Last edited on
Topic archived. No new replies allowed.