Sign in to follow this  
jsloan

std::string and Unicode problem

Recommended Posts

Is it possible that std::string find() function will not recognize certain characters? For example:
std::string test = "☺VERSION☺";

int result = test.find("☺");

//result always equals (-1) meaning it didnt find it


ok its formatting it into some WEIRD garbage here on the board, buts its a small smiley face type character.... thanks

Share this post


Link to post
Share on other sites
Are you sure your giving us the exact code as above because this works:


#include <string>
#include <iostream>

int main() {

std::string test("&#9786;VERSION&#9786;"), key("&#9786;");

std::string::size_type result = test.find(key);

if(result != std::string::npos)
std::cout << "found at pos: " << result << ", word: " << test.substr(result, key.length()) << std::endl;
else
std::cout << "Not found" << std::endl;

return 0;

}



All of those characters are in ascii character set, you don't need wstring unless you are going to use wide characters but i don't see that being the case.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this