Basically, it takes a vector, a string, and a few other optional parameters. It then searches through the vector till it find the string, and returns the index.
Problem? It works normally if I call it with x=get_index(search_vec,"search"), but if I pass in a string-type VARIABLE (string search="seach; get_index(seach_vec,search)), it can't find the string.Code:size_t get_index(vector<string>to_search, string search_str, size_t start=0, int error_number=0, string error_msg = "was not found!") { size_t x=start; if(error_number = 0) { error_number = to_search.size(); } if(to_search.empty()) { cout << search_str << " " << error_msg << "\n"; return error_number; } while(to_search[x] != search_str) { if(x == (to_search.size()-1)) { cout << search_str << " " << error_msg << "\n"; return 0; } x++; } return x; }
What's odd is that I don't recall it doing this before, so I'm not really sure what's changed.
Also, I've checked. It's not like it's not READING the strings, becuase I had to_search[x] be printed at each step of the while. It's just... not getting that they're equivalent.



LinkBack URL
About LinkBacks



