
Originally Posted by
Elysia
strcmp is oblivious to what a std::string is (it has no overload that takes a std::string), and no implicit conversion from std::string -> const char* exists, therefore it does not work. There is no need to use strcmp with std::string.
I am going to take it you did...
str1.compare(str2) < 0
...and if that is the case, you need to post an example of your code that demonstrates the problem.
Otherwise, you have a bug (though I don't think it should compile).
The same thing as str1.compare(str2) < 0.
Here it is. Its a function that, depending on whether the word is less than or greater than, assigns the read node to the left leaf or right leaf of a binary tree node.
Code:
struct masternode* insert(struct masternode* node, string token) {
if (node == NULL) {
return(NewNode(token));
}
else {
if (token.compare(node->token) < 0)
node->left = insert(node->left, token);
else if (token.compare(node->token) > 0)
node->right = insert(node->right, token);
else
(node->count)++;
return(node);
}
}