7

Вопрос по unicode, visual-studio-2010, c, c++ – Почему printf не форматирует параметры Unicode?

Error: User Rate Limit Exceeded

printf("%ls\n", L"s:\\яшертыHello");   // %ls for a wide string (%s varies meaning depending on the project's unicode settings).

Error: User Rate Limit Exceeded

s:\

Error: User Rate Limit Exceeded

s:\??????Hello

Error: User Rate Limit Exceeded

Error: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

UPDATE

Error: User Rate Limit Exceeded

  • Хороший пример того, как это сделать :)

    от
  • Error: User Rate Limit Exceededmsdn.microsoft.com/en-us/library/x99tb11d.aspxError: User Rate Limit Exceeded

    от Scott Langham
  • Error: User Rate Limit Exceeded

    от
  • Error: User Rate Limit Exceeded

    от
  • Error: User Rate Limit Exceededsprintf/printfError: User Rate Limit ExceededwsprintfAError: User Rate Limit Exceeded

    от Abyx
  • Error: User Rate Limit Exceeded

    от Scott Langham
  • Error: User Rate Limit Exceeded

    от Scott Langham
  • Error: User Rate Limit Exceeded

    от Scott Langham
  • Error: User Rate Limit Exceeded

    от Daniel Schlößer
  • 5

    Error: User Rate Limit Exceeded

    std::stringstream

    ostream & operator << ( ostream &os, const wchar_t * str )
    {
      if ( ( str == 0 ) || ( str[0] == L'\0' ) )
       return os;
      int new_size = WideCharToMultiByte( CP_UTF8, 0, str, -1, NULL, NULL, NULL, NULL );
      if ( new_size <= 0 )
        return os;
      std::vector<char> buffer(new_size);
      if ( WideCharToMultiByte( CP_UTF8, 0, str, -1, &buffer[0], new_size, NULL, NULL ) > 0 )
        os << &buffer[0];
      return os;
    }
    

    WideCharToMultiByte.

  • 12

    Error: User Rate Limit Exceeded

    #include <locale.h>
    #include <stdio.h>
    
    int main()
    {
        int c;
        char* l = setlocale(LC_ALL, "");
        if (l == NULL) {
            printf("Locale not set\n");
        } else {
            printf("Locale set to %s\n", l);
        }
        printf("%ls\n", L"s:\\яшертыHello");
        return 0;
    }
    

    $ env LC_ALL=en_US.utf8 ./a.out
    Locale set to en_US.utf8
    s:\яшертыHello