std::wstring_convert<Codecvt,Elem,Wide_alloc,Byte_alloc>:: converted
From cppreference.net
<
cpp
|
locale
|
wstring convert
C++
Text processing library
| Localization library | |||||||||||||||||||||||||
| Regular expressions library (C++11) | |||||||||||||||||||||||||
| Formatting library (C++20) | |||||||||||||||||||||||||
| Null-terminated sequence utilities | |||||||||||||||||||||||||
| Byte strings | |||||||||||||||||||||||||
| Multibyte strings | |||||||||||||||||||||||||
| Wide strings | |||||||||||||||||||||||||
| Primitive numeric conversions | |||||||||||||||||||||||||
|
|||||||||||||||||||||||||
| Text encoding identifications | |||||||||||||||||||||||||
|
|||||||||||||||||||||||||
Localization library
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
std::wstring_convert
| Member functions | ||||
|
wstring_convert::converted
|
||||
|
헤더에 정의됨
<locale>
|
||
|
std::
size_t
converted
(
)
const
noexcept
;
|
||
가장 최근의 from_bytes() 또는 to_bytes() 호출에서 성공적으로 처리된 소스 문자 수를 반환합니다.
목차 |
반환값
예제
이 코드 실행
#include <codecvt> #include <iostream> #include <locale> #include <string> int main() { std::string utf8 = "z\u00df\u6c34\U0001d10b"; // or u8"zß水𝄋" // or "\x7a\xc3\x9f\xe6\xb0\xb4\xf0\x9d\x84\x8b"; std::cout << "original UTF-8 string size: " << utf8.size() << '\n'; // the UTF-8 - UTF-32 standard conversion facet std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> cvt; // UTF-8 to UTF-32 std::u32string utf32 = cvt.from_bytes(utf8); std::cout << "UTF-32 string size: " << utf32.size() << '\n'; std::cout << "converted() == " << cvt.converted() << '\n'; // UTF-32 to UTF-8 utf8 = cvt.to_bytes(utf32); std::cout << "new UTF-8 string size: " << utf8.size() << '\n'; std::cout << "converted() == " << cvt.converted() << '\n'; }
출력:
original UTF-8 string size: 10 UTF-32 string size: 4 converted() == 10 new UTF-8 string size: 10 converted() == 4
결함 보고서
다음 동작 변경 결함 보고서는 이전에 게시된 C++ 표준에 소급 적용되었습니다.
| DR | 적용 대상 | 게시된 동작 | 올바른 동작 |
|---|---|---|---|
| LWG 2174 | C++11 |
wstring_convert::converted
에 noexcept 요구사항이 없었음
|
요구됨 |
참고 항목
|
와이드 문자열을 바이트 문자열로 변환
(public member function) |
|
|
바이트 문자열을 와이드 문자열로 변환
(public member function) |