本文整理汇总了C++中std::basic_ostream::narrow方法的典型用法代码示例。如果您正苦于以下问题:C++ basic_ostream::narrow方法的具体用法?C++ basic_ostream::narrow怎么用?C++ basic_ostream::narrow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::basic_ostream
的用法示例。
在下文中一共展示了basic_ostream::narrow方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fprint
//.........这里部分代码省略.........
if(Trait::eq(*str, out.widen('$'))) {
has_positional = true;
++str;
}
// check for [flags]
// they are as follows:
// + - equivalent to std::showpos
// - - left aligns instead of right align, i.e. std::left
// 0 - pad with 0s instead of spaces
// '[char] - pad with [char] instead of spaces
while(*str) {
if(Trait::eq(*str, out.widen('+'))) {
changed.flags |= out.showpos;
}
else if(Trait::eq(*str, out.widen('-'))) {
changed.flags |= out.left;
}
else if(Trait::eq(*str, out.widen('0'))) {
changed.fill = out.widen('0');
}
else if(Trait::eq(*str, out.widen('\''))) {
// the next character is unconditionally the fill character
changed.fill = *(++str);
}
else {
// unknown flag, so just exit
break;
}
++str;
}
// check for [width]
changed.width = parse_integer(str, zero, loc);
// check for [precision]
if(Trait::eq(*str, out.widen('.'))) {
changed.precision = parse_integer(++str, zero, loc);
}
size_t final_index = has_positional ? position - 1 : index++;
// check for verb
if(Trait::eq(*str, out.widen('s')) || Trait::eq(*str, out.widen('c'))) {
// do nothing since these don't add any extra format specifiers.
// many of these are provided as a thin compatibility layer for
// the original printf -- albeit strict compatibility is not a requirement here.
}
else if(Trait::eq(*str, out.widen('f')) || Trait::eq(*str, out.widen('F'))) {
changed.flags |= out.fixed;
}
else if(Trait::eq(*str, out.widen('e'))) {
changed.flags |= out.scientific;
}
else if(Trait::eq(*str, out.widen('E'))) {
changed.flags |= out.scientific;
changed.flags |= out.uppercase;
}
else if(Trait::eq(*str, out.widen('g'))) {
changed.flags &= ~out.floatfield;
}
else if(Trait::eq(*str, out.widen('G'))) {
changed.flags &= ~out.floatfield;
changed.flags |= out.uppercase;
}
else if(Trait::eq(*str, out.widen('x')) || Trait::eq(*str, out.widen('p'))) {
changed.flags |= out.hex;
}
else if(Trait::eq(*str, out.widen('X'))) {
changed.flags |= out.hex;
changed.flags |= out.uppercase;
}
else if(Trait::eq(*str, out.widen('d')) || Trait::eq(*str, out.widen('i')) || Trait::eq(*str, out.widen('u'))) {
changed.flags |= out.dec;
}
else if(Trait::eq(*str, out.widen('o'))) {
changed.flags |= out.oct;
}
else {
std::string error = "invalid verb given ";
auto narrowed = out.narrow(*str, 0x00);
if(narrowed == 0x00) {
error.push_back('\'');
error.push_back(narrowed);
error.push_back('\'');
}
else {
error.append(" (unable to convert to char)");
}
throw std::runtime_error(error);
}
changed.apply(out);
apply(args, final_index, func);
original.apply(out);
++str;
}
}