Hi folks,
I'd like your opinion on which of the two functions are faster:
VERSUS:Code:string& Index::Convert(string& word) { string::iterator it; it = &word[0]; while(it != word.end()) { if(*it == '_') { *it = ' '; // converts '_' into a space. } ++it; } return word; }
I'm inclined to believe the first is faster, since it only iterates through the string once, but I'm not sure.Code:string& Index::Convert(string& word) { double wordlength = word.length(); double count = 0; for (double i = 0; i<=wordlength; i++) { if (word[i] == '_') { word[i] = ' '; //converts a '_' into a space } } return word; }




Reply With Quote