0

I am not a very experienced C++ programmer, i get a warning when i do the following:

if (myString[i] != 'x')
{
}

what is the appropriate way to compare these?

thanks for your help!

skaffman
  • 398,947
  • 96
  • 818
  • 769
Jorge
  • 33
  • 4
  • What warning are you getting? I see nothing inherently wrong with this code – JaredPar Oct 25 '09 at 18:21
  • I get no warning on G++ - what warning are you getting? – bdonlan Oct 25 '09 at 18:21
  • bah i was using a long long int, your comments led me to it thank you! the warning was: warning C4244: 'argument' : conversion from 'unsigned __int64' to 'unsigned int', possible loss of data – Jorge Oct 25 '09 at 18:23
  • Is myString full of wide characters (unicode)? If so, you would have to do, myString[i] != L'x' – popester Oct 25 '09 at 18:28
  • @Jorge, a bit of advice for the future: You can edit your own question ('edit' link below the tags), and if you figure out the answer to your own question, feel free to put it in as an answer below, so your question shows up as answered (you can also accept your own answer after 48 hours) – bdonlan Oct 25 '09 at 18:36
  • Now that someone has answered it, he can't delete his own question (I don't think). But he can add his own solution as an answer below and accept it, or accept Jorge's. – bdonlan Oct 25 '09 at 18:47

1 Answers1

2

possibility 1: the int that identifies the element in the array should not be larger than a regular int.

possibility 2: If myString is of type std::wstring the appropriate comparison is myString[i] != L'x' (ty popester!)

Jorge
  • 33
  • 4