string.at error

i need some advice i cant get the results im looking for and im completely lost.
i want to take only the THIRD character of a 5 letter string and cout the correct message
short ex.
12b35 couts Blue.
12w34 couts white
12g34 couts green
12r45 couts red

i dont know whats going wrong its take the third character but i dont want it to cout everything just the correct message. help?
thirdcahr is third character of the string.

here's the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
switch(thirdchar)
{
   case 'b':
      cout << "Blue" ;
      break;
   case 'w':
      cout << "White" ;
      break;
   case 'g':
      cout << "Green" ;
      break;
   case 'r':
      cout << "Red" ;
      break;
}
yeah ive done that it must be the way im searching for the third character in the string
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
switch(item.at(2)==letter)
{
   case 'B':
      cout << "Blue" ;
      break;
   case 'W':
      cout << "White" ;
      break;
   case 'G':
      cout << "Green" ;
      break;
   case 'R':
      cout << "Red" ;
      break;
}










switch(item.at(2)==letter)
This is either true or false, not B, W, G, R. The switch structure always compare on equality (put a default for debug)
Should be switch(item.at(2))

Also be careful with uppercase and lowercase
Topic archived. No new replies allowed.