std::codecvt::in
STD::codecvt::in,std::codecvt::do[医]在
Defined in header | | |
---|---|---|
public: result in( StateT& state, const ExternT* from, const ExternT* from_end, const ExternT*& from_next, InternT* to, InternT* to_end, InternT*& to_next ) const; | (1) | |
protected: virtual result do_in( StateT& state, const ExternT* from, const ExternT* from_end, const ExternT*& from_next, InternT* to, InternT* to_end, InternT*& to_next ) const; | (2) | |
1%29公共成员函数,调用成员函数do_in
最派生的类。
2%29如果这个codecvt
方面定义转换,从源范围翻译外部字符。[from, from_end)
对于内部字符,将结果放在后面的位置,从to
皈依者不得超过from_end - from
外部字符和写入不超过to_end - to
内部人物。叶from_next
和to_next
指向最后一个元素之后的一个元素成功转换。
如果这个codecvt
facet不定义转换,也不转换字符。to_next
设置为等于to
,,,state
没有变化,而且std::codecvt_base::noconv
会被归还。
返回值
类型值std::codecvt_base::result
,说明成功情况如下:
ok | conversion completed |
---|---|
partial | not enough space in the output buffer or unexpected end of source buffer |
error | encountered a character that could not be converted |
noconv | this facet is non-converting, no output written |
非转换专业化std::codecvt<char, char,std::mbstate_t>总是回来std::codecvt_base::noconv...
注记
要求from <= from_end && to <= to_end而那state要么表示初始移位状态,要么通过转换序列中的前面的字符获得。
对...的影响state
是故意不指定的。在标准方面中,它用于维护Shift状态,如调用时一样。std::mbsrtowcs
,因此更新以反映上次处理的外部字符之后的转换状态,但是用户定义的方面可以使用它来维护任何其他状态,例如,计算遇到的特殊字符数。
例
二次
#include <iostream>
#include <string>
#include <locale>
int main()
{
std::locale::global(std::locale("en_US.utf8")
auto& f = std::use_facet<std::codecvt<wchar_t, char, std::mbstate_t>>(std::locale()
std::string external = u8"z\u00df\u6c34\U0001d10b"; // or u8"zß水?"
// or "\x7a\xc3\x9f\xe6\xb0\xb4\xf0\x9d\x84\x8b";
// note that the following can be done with wstring_convert
std::mbstate_t mb = std::mbstate_t( // initial shift state
std::wstring internal(external.size(), '\0'
const char* from_next;
wchar_t* to_next;
f.in(mb, &external[0], &external[external.size()], from_next,
&internal[0], &internal[internal.size()], to_next
// error checking skipped for brevity
internal.resize(to_next - &internal[0]
std::wcout << L"The string in wide encoding: " << internal << '\n';
}
二次
产出:
二次
The string in wide encoding: zß水?
二次
另见
underflow virtual | reads from the associated file (virtual protected member function of std::basic_filebuf) |
---|---|
from_bytes | converts a byte string into a wide string (public member function of std::wstring_convert) |
mbsrtowcs | converts a narrow multibyte character string to wide string, given state (function) |
do_out virtual | converts a string from internT to externT, such as when writing to file (virtual protected member function) |
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。