0

I was wondering if any of you could help me with a problem I'm having. Currently I have a function that takes in a c-style string, creates a temporary c++ style string and store the c string into it, and uses the find_first_not_of command to look for invalid characters, some of which include french characters like 'à'. However, when I pass in a string containing french characters, it doesn't recognize them as valid.

I am using visual studio 2013 on Windows 8, and a few people have told me that the issue is that how VS encodes it's files is different then how it encodes input from the command prompt, but I do not know how to fix that. Do any of you know how I would go about doing this? Or is is a different problem with my code entirely?

My code for the function is as follow:

bool checkValidCharacters(const char* input)
{
    std::string checkString(input);
    bool validCharacters = false;
    std::size_t found = checkString.find_first_not_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZàâäèêëîôùûüÿçÀÂÄÈÉÊÎÏÔÙÛÜŸÇ-. ");
    if (found != std::string::npos)
    {
        printf("Error: Invalid character: %c", input[found]);
    }
    else
    {
        printf("All characters valid\n");
        validCharacters = true;
    }
    return validCharacters;
}

Thanks a bunch.

hlscalon
  • 7,304
  • 4
  • 33
  • 40
Hayden Taylor
  • 65
  • 1
  • 9
  • 2
    if `à` is a Unicode then you need to use a `wstring` – NathanOliver Mar 10 '15 at 18:41
  • http://stackoverflow.com/questions/388490/unicode-characters-in-windows-command-line-how (note that my test with a UTF-8 euro symbol didn't display properly with the raster font, but still worked). – chris Mar 10 '15 at 18:41
  • Just to confirm your code works fine http://rextester.com/UGB48805. (As you said, the problem must be something else). This may help you out http://stackoverflow.com/questions/12276757/change-encoding-on-a-per-file-or-per-extension-basis or https://vlasovstudio.com/fix-file-encoding/ – hlscalon Mar 10 '15 at 18:47

0 Answers0