Hi guys
I currently have a program with the following string: string keyboard="qwertyuiopasdfghjkl0zxcvbnm000";
and the second string: string input="a";
when I try to find the value of input[0] ('a') using the find algorithm I am not able to retrieve the cell in the keyboard string the letter a is saved in:
find(keyboard.begin(), keyboard.end(), input[0]);
if i put * in front of the find function it just returns the letter itself and if i use & instead it returns the memory address of the letter within keyboard.
is there any way i can instead get the cell of keyboard, the letter a is stored in? (using the find function or any other algorithm)
i could just use a for loop running through keyboard in order to search the cell but i think there might be something more efficient in the library :S
greetings
//EDIT:
for the sake of clarity: if i search for 'a' it is supposed to return a value of 10 since a is in the tenth cell of keyboard
//EDIT2:
sorry, this was supposed to go into the beginners forum -.-
std::find returns an iterator value of which is equal to input[0] in case of success or keyboard.end() in case of failure.
It is much better to use member functions of class string for this purpose. For example
1 2 3 4
auto pos = keyboard.find( inpuut[0] );
if ( pos != std::string::npos ) std:;cout << "The target character is in position " << pos << std::end;
else std::cout << "Character " << input[0] << " is not found\n";
I'm assuming the find you're using is the one found in the algorithm library, which if I'm not misstaken returns an iterator (not the letter) starting at the position of where you can find 'a'.