ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • sprintf
    C++ Builder/함수 2018. 12. 6. 22:07

    #sprintf

    System.UnicodeString.sprintf

    C++

    UnicodeString& __cdecl         sprintf(const wchar_t* format, ...); // Returns *this

    Properties

    Type

    Visibility

    Source

    Unit

    Parent

    function

    public

    ustring.h

    System

    UnicodeString

    Description

    Sets the value of UnicodeString, given the format string and its arguments.

    Use sprintf to set to the value of the UnicodeString instance, given a standard C++ format specifier. Pass the values to any arguments in the format specifier as additional parameters following the format parameter.

    This method returns a reference to the UnicodeString instance (*this) with the resulting value.

    Warning: The value returned by UnicodeString.c_str() under OS X and iOS is char16_t* while the sprintf function expects wchar_t*.


    Note:

    UnicodeString.sprintf() does not support %ls on the OS X platform.


    String myString = myString.sprintf(L"Float Value Formatted : %2.5f", floatValue);

     

    참고로 위와 같은 경우 C 스타일 문자열 앞에 대문자 'L'을 넣어줘야 합니다. 이것은 기존 C 스타일 문자열을 Unicode String으로 인식되도록 합니다.


    출처: http://xho95.tistory.com/9 [Everything in C++ Builder]


    wchar_t의 문자열 앞의 대문자 L은 컴파일러가 문자열을 유니코드로 다루도록 한다. 컴파일러가 문자열을 데이터 섹션에 삽입할 때 각 문자들은 UTF-16으로 인코딩된다.


    char c = ‘a’; //ansi 형태 1바이트의 크기

    wchar_t ct = L’a’; //유니코드 형태 2바이트의 크기


    char* StrAnsi = “EUNSU”; // const char *

    wchar_t* StrUnicode = L”EUNSU”; // const wchar_t *

    ex){

    int i = 5;

    UnicodeString TestString ;

    TestString.sprintf(L"asd %d",i);

    ShowMessage(TestString);

    }



    728x90

    'C++ Builder > 함수' 카테고리의 다른 글

    Pos  (0) 2018.12.06
    Delete  (0) 2018.12.06
    Insert  (0) 2018.12.06
    Length  (0) 2018.12.06
    c_str  (0) 2018.12.06

    댓글

Designed by Tistory.