in
描述 (Description)
它用于转换字符,并且一旦转换字符失败,或者一旦到达from_end并且其字符成功转换,函数就会停止转换。
声明 (Declaration)
以下是std :: ctype :: in的声明。
C++98
result in (state_type& state,
const extern_type* from, const extern_type* from_end, const extern_type*& from_next,
intern_type* to, intern_type* to_limit, intern_type*& to_next) const;
C++11
result in (state_type& state,
const extern_type* from, const extern_type* from_end, const extern_type*& from_next,
intern_type* to, intern_type* to_limit, intern_type*& to_next) const;
参数 (Parameters)
state - 它是一个状态对象。
from, from_end - 用于查找源序列的初始和最终字符。
from_next - 用于查找上述范围内的元素。
to_next - 用于查找上述范围内的元素。
返回值 (Return Value)
它返回codecvt_base :: result。
异常 (Exceptions)
如果抛出异常,则facet对象中没有更改,但范围中的字符可能已受到影响。
数据竞争 (Data races)
访问该对象以及[低,高]范围内的元素。
例子 (Example)
在下面的例子中解释了std :: ctype :: in。
#include <iostream>
#include <locale>
#include <string>
#include <cwchar>
int main () {
typedef std::codecvt<wchar_t,char,std::mbstate_t> facet_type;
std::locale mylocale;
const facet_type& myfacet = std::use_facet<facet_type>(mylocale);
const char mystr[] = "iowiki.com";
wchar_t pwstr[sizeof(mystr)];
std::mbstate_t mystate = std::mbstate_t();
const char* pc;
wchar_t* pwc;
facet_type::result myresult = myfacet.in (mystate,
mystr, mystr+sizeof(mystr), pc, pwstr, pwstr+sizeof(mystr), pwc);
if ( myresult == facet_type::ok ) {
std::wcout << L"Translation was successful: ";
std::wcout << pwstr << std::endl;
}
return 0;
}
让我们编译并运行上面的程序,这将产生以下结果 -
Translation was successful: iowiki.com