Comparing a string to an int

Is is possible to compare a string to an int inside of a while loop? Essentially, I'm making an RPG. I want to allow the user to enter the names of their 4 characters before the game even starts (similar to the first Final Fantasy on the NES). I don't want the user to enter a name 10 characters or longer.

After the part where they cin their name choice, can I use a while loop like this? (members[i].name is what they entered their name into)

1
2
3
4
5
  while( members[i].name >= 10)
  {
     cout << "Please type in a name less than 10 characters long."
     cin >> members[i].name
  }


Or are you unable to compare a string to an int like that? If I can't do it this way, what would be an alternative?
You can use the length() member function to get the length of the string, and compare with that.

while( members[i].name.length() >= 10)
Topic archived. No new replies allowed.