本文整理汇总了C++中ios_base::width方法的典型用法代码示例。如果您正苦于以下问题:C++ ios_base::width方法的具体用法?C++ ios_base::width怎么用?C++ ios_base::width使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ios_base
的用法示例。
在下文中一共展示了ios_base::width方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: do_put
num_put<Pt::Char, ostreambuf_iterator<Pt::Char> >::iter_type
num_put<Pt::Char, ostreambuf_iterator<Pt::Char> >::do_put(iter_type s, ios_base& f, char_type fill, bool val) const
{
if( 0 == (f.flags() & ios_base::boolalpha) )
return do_put(s, f, fill, static_cast<long>(val));
typedef Pt::Char char_type;
const numpunct<char_type>& np = use_facet< numpunct<char_type> >( f.getloc() );
Pt::String str = val ? np.truename() : np.falsename();
streamsize width = f.width(0);
if( str.size() >= static_cast<std::size_t>(width) )
{
return std::copy(str.begin(), str.end(), s);
}
streamsize pad = width - str.size();
ios_base::fmtflags dir = f.flags() & ios_base::adjustfield;
if (dir == ios_base::left)
{
std::copy(str.begin(), str.end(), s);
std::fill_n(s, pad, fill);
return s;
}
// right/internal padding
std::fill_n(s, pad, fill);
return std::copy(str.begin(), str.end(), s);
}
示例2: putHex
num_put<Pt::Char, ostreambuf_iterator<Pt::Char> >::iter_type
num_put<Pt::Char, ostreambuf_iterator<Pt::Char> >::do_put(iter_type s, ios_base& f, char_type fill, const void* ptr) const
{
std::size_t val = reinterpret_cast<std::size_t>(ptr);
putHex(s, val, f.flags(), f.width(0), fill);
return s;
}
示例3: switch
num_put<Pt::Char, ostreambuf_iterator<Pt::Char> >::iter_type
num_put<Pt::Char, ostreambuf_iterator<Pt::Char> >::do_put(iter_type s, ios_base& f, char_type fill, unsigned long long val) const
{
// TODO: grouping
//const numpunct<char>& np = use_facet<numpunct<char> >(f.getloc());
//const string& grouping = np.grouping();
switch (f.flags() & ios_base::basefield)
{
case ios_base::oct:
putOctal(s, val, f.flags(), f.width(0), fill);
break;
case ios_base::hex:
putHex(s, val, f.flags(), f.width(0), fill);
break;
default:
putDecimal(s, val, f.flags(), f.width(0), fill);
break;
}
return s;
}
示例4: __copy_float_and_fill
_OutputIter _STLP_CALL
__put_float(__iostring &__str, _OutputIter __oi,
ios_base& __f, char __fill,
char __decimal_point, char __sep,
size_t __group_pos, const string& __grouping) {
if ((__group_pos < __str.size()) && (__str[__group_pos] == '.')) {
__str[__group_pos] = __decimal_point;
}
if (!__grouping.empty()) {
__insert_grouping(__str, __group_pos,
__grouping, __sep, '+', '-', 0);
}
return __copy_float_and_fill(__CONST_CAST(char*, __str.data()),
__CONST_CAST(char*, __str.data()) + __str.size(), __oi,
__f.flags(), __f.width(0), __fill, '+', '-');
}
示例5: putFloat
num_put<Pt::Char, ostreambuf_iterator<Pt::Char> >::iter_type
num_put<Pt::Char, ostreambuf_iterator<Pt::Char> >::do_put(iter_type s, ios_base& f, char_type fill, long double val) const
{
putFloat(s, val, f.flags(), f.width(0), fill, f.precision());
return s;
}
示例6: while
_OutputIter _S_do_put(_OutputIter __s, bool __intl, ios_base& __str,
_CharT __fill, const _Str& __digits, bool __check_digits,
_Str_Type * /*__dummy*/) {
typedef _CharT char_type;
typedef _Str_Type string_type;
typedef ctype<char_type> _Ctype;
typedef moneypunct<char_type, false> _Punct;
typedef moneypunct<char_type, true> _Punct_intl;
locale __loc = __str.getloc();
const _Ctype& __c_type = use_facet<_Ctype>(__loc) ;
const _Punct& __punct = use_facet<_Punct>(__loc) ;
const _Punct_intl& __punct_intl = use_facet<_Punct_intl>(__loc) ;
// some special characters
char_type __minus = __c_type.widen('-');
char_type __plus = __c_type.widen('+');
char_type __space = __c_type.widen(' ');
char_type __zero = __c_type.widen('0');
char_type __point = __intl ? __punct_intl.decimal_point()
: __punct.decimal_point();
char_type __sep = __intl ? __punct_intl.thousands_sep()
: __punct.thousands_sep();
string __grouping = __intl ? __punct_intl.grouping()
: __punct.grouping();
int __frac_digits = __intl ? __punct_intl.frac_digits()
: __punct.frac_digits();
string_type __curr_sym = __intl ? __punct_intl.curr_symbol()
: __punct.curr_symbol();
// if there are no digits we are going to return __s. If there
// are digits, but not enough to fill the frac_digits, we are
// going to add zeros. I don't know whether this is right or
// not.
if (__digits.empty())
return __s;
typename string_type::const_iterator __digits_first = __digits.begin();
typename string_type::const_iterator __digits_last = __digits.end();
bool __is_negative = *__digits_first == __minus;
if (__is_negative)
++__digits_first;
string_type __sign = __intl ? __is_negative ? __punct_intl.negative_sign()
: __punct_intl.positive_sign()
: __is_negative ? __punct.negative_sign()
: __punct.positive_sign();
if (__check_digits) {
typename string_type::const_iterator __cp = __digits_first;
while (__cp != __digits_last && __c_type.is(ctype_base::digit, *__cp))
++__cp;
if (__cp == __digits_first)
return __s;
__digits_last = __cp;
}
// If grouping is required, we make a copy of __digits and
// insert the grouping.
_STLP_BASIC_IOSTRING(char_type) __new_digits;
if (!__grouping.empty()) {
__new_digits.assign(__digits_first, __digits_last);
__insert_grouping(__new_digits,
__new_digits.size() - __frac_digits,
__grouping,
__sep, __plus, __minus, 0);
__digits_first = __new_digits.begin(); // <<--
__digits_last = __new_digits.end(); // <<--
}
// Determine the amount of padding required, if any.
streamsize __width = __str.width();
#if defined(_STLP_DEBUG) && (defined(__HP_aCC) && (__HP_aCC <= 1))
size_t __value_length = operator -(__digits_last, __digits_first);
#else
size_t __value_length = __digits_last - __digits_first;
#endif
size_t __length = __value_length + __sign.size();
if (__frac_digits != 0)
++__length;
bool __generate_curr = (__str.flags() & ios_base::showbase) !=0;
if (__generate_curr)
__length += __curr_sym.size();
money_base::pattern __format = __intl ? (__is_negative ? __punct_intl.neg_format()
: __punct_intl.pos_format())
: (__is_negative ? __punct.neg_format()
: __punct.pos_format());
{
//For the moment the following is commented for decoding reason.
//No reason to add a space last if the money symbol do not have to be display
//if (__format.field[3] == (char) money_base::symbol && !__generate_curr) {
//.........这里部分代码省略.........