indexing maps and strings(C++)

Started by
1 comment, last by thekguy 14 years, 8 months ago
okay, so i have an input file of two lines which i stored in 2 strings, 1 for each line. i have to multiply the letters of the string, where a = 1...z = 26, so i have a map<char, int> with all the pairs already initialized. the strings and map are all good, i output the strings and they're right and the map works fine with regular chars... yet when i index the map with chars that i in turn indexed from the string, i always get 0. so if i have a string like ABABA i expect 1*2*1*2*1 yet i get 0*0*0*0*0 the only reason i can think for this is that it didn't recognize the key i used and instead value-initialized a new int...why?
Advertisement
In short, it's because 'a' != 'A'.

Why are you using a map<char, int>? Using regular math, 'a' - 'a' + 1 == 1 and 'z' - 'a' + 1 == 26
oh lol -_-

hm. i feel kinda stupid now.

thanks!

This topic is closed to new replies.

Advertisement