当前位置: 首页>>代码示例>>C++>>正文


C++ basic_ostream::flags方法代码示例

本文整理汇总了C++中std::basic_ostream::flags方法的典型用法代码示例。如果您正苦于以下问题:C++ basic_ostream::flags方法的具体用法?C++ basic_ostream::flags怎么用?C++ basic_ostream::flags使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在std::basic_ostream的用法示例。


在下文中一共展示了basic_ostream::flags方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: write_ascii

 void write_ascii(std::basic_ostream<charT, traits>& os) const {
     typename std::basic_ostream<charT, traits>::fmtflags save = os.flags();
     size_t index_size = (size_t)1 << (num_indexed_chars*2);
     for (size_t i = 0; i != index_size; ++i) {
         for (index_type j = index[i]; j != index[i+1]; ++j) {
             addr_type a = addr[j];
             os << "[" << a << " " << string->substr(a, num_indexed_chars) << "]";
         }
         os << "\n";
     }
     os.setstate( save );
 }
开发者ID:RickOne16,项目名称:genetics,代码行数:12,代码来源:two_stage_index.hpp

示例2: insert_aligned

 void insert_aligned(std::basic_ostream<charT, traits>& os, const basic_string_ref<charT,traits>& str) {
     const std::size_t size = str.size();
     const std::size_t alignment_size = static_cast< std::size_t >(os.width()) - size;
     const bool align_left = (os.flags() & std::basic_ostream<charT, traits>::adjustfield) == std::basic_ostream<charT, traits>::left;
     if (!align_left) {
         detail::insert_fill_chars(os, alignment_size);
         if (os.good())
             os.write(str.data(), size);
         }
     else {
         os.write(str.data(), size);
         if (os.good())
             detail::insert_fill_chars(os, alignment_size);
         }
     }
开发者ID:imos,项目名称:icfpc2015,代码行数:15,代码来源:string_ref.hpp

示例3: fprint

inline void fprint(std::basic_ostream<Elem, Traits>& out, const std::basic_string<Elem, Traits>& str, Args&&... arguments) {
    if(sizeof...(arguments) < 1) {
        out << str;
        return;
    }

    auto args = std::make_tuple(std::forward<Args>(arguments)...);

    string::is_digit cmp;
    auto&& length = str.size();
    auto&& original_width = out.width();
    std::ios_base::fmtflags original_format = out.flags();
    auto&& original_precision = out.precision();

    for(decltype(str.size()) i = 0; i < length; ++i) {
        auto&& c = str[i];
        // doesn't start with { so just print it and continue
        if(c != out.widen('{')) {
            out << c;
            continue;
        }

        // at this point, the character c points to {
        // check if we're done printing
        if(i + 1 > length) {
            out << c;
            break;
        }

        // check the next characters
        auto j = i + 1;
        unsigned index = 0;
        decltype(out.width()) width = 0;
        decltype(out.precision()) precision = 0;
        auto format = original_format;

        // escaped character
        if(str[j] == out.widen('{')) {
            out << str[i];
            i = j;
            continue;
        }

        // now we're at a sane point where we can work with the format string
        // check if the next character is a digit
        if(cmp(str[j])) {
            do {
                // since it is, multiply the index
                index = (index * 10) + (str[j++] - out.widen('0'));
            }
            while(j < length && cmp(str[j]));
        }
        else {
            // since it isn't a digit, it doesn't match our format string
            throw std::runtime_error("invalid format string specified");
        }

        // check if alignment argument exists
        if(str[j] == out.widen(',')) {
            // check if the next character is valid
            if(j + 1 < length) {
                // check if the alignment is left or right
                if(str[j + 1] == out.widen('-')) {
                    format |= out.left;
                    // increment by two to get to the numerical section
                    j += 2;
                }
                else {
                    format |= out.right;
                    ++j;
                }
                // check if the next character is a digit
                if(j < length && cmp(str[j])) {
                    do {
                        // since it is, multiply the width
                        width = (width * 10) + (str[j++] - out.widen('0'));
                    }
                    while(j < length && cmp(str[j]));
                }
                else {
                    // invalid format string found
                    throw std::runtime_error("invalid format string specified");
                }

            }
        }

        // check if format specifier exists
        if(str[j] == out.widen(':')) {
            // check if the character is valid
            if(j + 1 < length) {
                auto&& specifier = str[j + 1];
                switch(specifier) {
                case 'F':
                    format |= out.fixed;
                    break;
                case 'O':
                    format = (format & ~out.basefield) | out.oct;
                    break;
                case 'x':
//.........这里部分代码省略.........
开发者ID:Rapptz,项目名称:Gears,代码行数:101,代码来源:fprint.hpp


注:本文中的std::basic_ostream::flags方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。