• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ std::basic_ostream类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: out_quote

inline void out_quote(std::basic_ostream<Ch, Tr> &out, const C& data, IsSpecial is_special = IsSpecial(), char quote_char='"', char escape_char='\\') {
  std::basic_stringstream<Ch, Tr> s;
  s << data;
  or_true_for_chars<IsSpecial> needs_quote(quote_char, escape_char, is_special);
  typedef std::istreambuf_iterator<Ch, Tr> i_iter;
  typedef std::ostream_iterator<Ch, Tr> o_iter;
  i_iter i(s), end;
  bool quote = (std::find_if (i, end, needs_quote) != end);
  rewind(s);
  if (quote) {
    out << quote_char;
    for (i_iter i(s); i!=end; ++i) {
      Ch c=*i;
      if (c == quote_char || c== escape_char)
        out.put(escape_char);
      out.put(c);
    }
    out << quote_char;
  } else {
    //        std::copy(i_iter(s),end,o_iter(out));
    /*
      for (i_iter i(s);i!=end;++i)
      out.put(*i);
    */
    Ch c;
    while (s.get(c))
      out.put(c);
  }
}
开发者ID:zjucsxxd,项目名称:carmel,代码行数:29,代码来源:quote.hpp


示例2: print

void
print(
	std::basic_ostream<
		Ch,
		Traits
	> &_stream,
	fcppt::container::tree::object<
		Value
	> const &_tree,
	unsigned const _indent
)
{
	for(
		unsigned index = 0;
		index < _indent;
		++index
	)
		_stream
			<< _stream.widen('\t');

	_stream
		<< _tree.value()
		<< _stream.widen('\n');

	for(
		auto child : _tree
	)
		fcppt::container::tree::detail::print(
			_stream,
			child,
			_indent + 1u
		);
}
开发者ID:amoylel,项目名称:fcppt,代码行数:33,代码来源:print.hpp


示例3: write_json_helper

    void write_json_helper(std::basic_ostream<typename Ptree::char_type> &stream, 
                           const Ptree &pt, 
                           int indent)
    {

        typedef typename Ptree::char_type Ch;
        typedef typename std::basic_string<Ch> Str;
        
        // Value or object or array
        if (indent > 0 && pt.empty())
        {
            
            // Write value
            Str data = create_escapes(pt.template get_own<Str>(), stream.getloc());
            stream << Ch('"') << data << Ch('"');

        }
        else if (indent > 0 && pt.count(Str()) == pt.size())
        {
                
            // Write array
            stream << Ch('[') << Ch('\n');
            typename Ptree::const_iterator it = pt.begin();
            for (; it != pt.end(); ++it)
            {
                stream << Str(4 * (indent + 1), Ch(' '));
                write_json_helper(stream, it->second, indent + 1);
                if (boost::next(it) != pt.end())
                    stream << Ch(',');
                stream << Ch('\n');
            }
            stream << Str(4 * indent, Ch(' ')) << Ch(']');

        }
        else
        {
        
            // Write object
            stream << Ch('{') << Ch('\n');
            typename Ptree::const_iterator it = pt.begin();
            for (; it != pt.end(); ++it)
            {
                stream << Str(4 * (indent + 1), Ch(' '));
                stream << Ch('"') << create_escapes(it->first, stream.getloc()) << Ch('"') << Ch(':');
                if (it->second.empty())
                    stream << Ch(' ');
                else
                    stream << Ch('\n') << Str(4 * (indent + 1), Ch(' '));
                write_json_helper(stream, it->second, indent + 1);
                if (boost::next(it) != pt.end())
                    stream << Ch(',');
                stream << Ch('\n');
            }
            stream << Str(4 * indent, Ch(' ')) << Ch('}');

        }

    }
开发者ID:craton-,项目名称:php_mapnik,代码行数:58,代码来源:json_parser_write.hpp


示例4: insert_fill_chars

 inline void insert_fill_chars(std::basic_ostream<charT, traits>& os, std::size_t n) {
     enum { chunk_size = 8 };
     charT fill_chars[chunk_size];
     std::fill_n(fill_chars, static_cast< std::size_t >(chunk_size), os.fill());
     for (; n >= chunk_size && os.good(); n -= chunk_size)
         os.write(fill_chars, static_cast< std::size_t >(chunk_size));
     if (n > 0 && os.good())
         os.write(fill_chars, n);
     }
开发者ID:imos,项目名称:icfpc2015,代码行数:9,代码来源:string_ref.hpp


示例5: out_string_always_quote

inline void out_string_always_quote(std::basic_ostream<Ch, Tr> &out, S const& s)
{
  out << '"';
  for (typename S::const_iterator i = s.begin(), e = s.end(); i!=e; ++i) {
    char c=*i;
    if (c == '"' || c== '\\')
      out.put('\\');
    out.put(c);
  }
  out << '"';
}
开发者ID:zjucsxxd,项目名称:carmel,代码行数:11,代码来源:quote.hpp


示例6: out_always_quote

inline void out_always_quote(std::basic_ostream<Ch, Tr> &out, const C& data) {
  std::basic_stringstream<Ch, Tr> s;
  s << data;
  char c;
  out << '"';
  while (s.get(c)) {
    if (c == '"' || c== '\\')
      out.put('\\');
    out.put(c);
  }
  out << '"';
}
开发者ID:zjucsxxd,项目名称:carmel,代码行数:12,代码来源:quote.hpp


示例7: 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


示例8: write

 ///
 /// Translate message and write to stream \a out, using imbued locale and domain set to the 
 /// stream
 ///
 void write(std::basic_ostream<char_type> &out) const
 {
     std::locale const &loc = out.getloc();
     int id = ios_info::get(out).domain_id();
     string_type buffer;
     out << write(loc,id,buffer);
 }
开发者ID:imos,项目名称:icfpc2015,代码行数:11,代码来源:message.hpp


示例9:

basic_csv_ostream<Char, Traits>::basic_csv_ostream
(std::basic_ostream<Char, Traits> & os)
    : os_(os)
    , delim_(os.widen(COMMA))
    , quote_(os.widen(QUOTE))
    , first_(true)
{}
开发者ID:jorgemarsal,项目名称:text-csv,代码行数:7,代码来源:ostream.hpp


示例10: write_info_internal

 void write_info_internal(std::basic_ostream<typename Ptree::char_type> &stream, 
                          const Ptree &pt,
                          const std::string &filename)
 {
     write_info_helper(stream, pt, -1);
     if (!stream.good())
         throw info_parser_error("write error", filename, 0);
 }
开发者ID:craton-,项目名称:php_mapnik,代码行数:8,代码来源:info_parser_write.hpp


示例11: write_info_internal

 void write_info_internal(std::basic_ostream<typename Ptree::key_type::value_type> &stream, 
                          const Ptree &pt,
                          const std::string &filename,
                          const info_writer_settings<typename Ptree::key_type::value_type> &settings)
 {
     write_info_helper(stream, pt, -1, settings);
     if (!stream.good())
         BOOST_PROPERTY_TREE_THROW(info_parser_error("write error", filename, 0));
 }
开发者ID:ALuehmann,项目名称:labstreaminglayer,代码行数:9,代码来源:info_parser_write.hpp


示例12: validate

            bool validate(std::basic_ostream<Char>& out) const {
                typename std::basic_ostream<Char>::streampos current =
                    out.tellp();
                out.seekp(0, std::ios::end);
                uint32_t file_size = static_cast<uint32_t>(out.tellp());
                out.seekp(current, std::ios::beg);
                uint32_t supposed_size =
                    data_subchunk.size + sizeof(header_type);

                if (file_size != supposed_size) {
                    DBGLOG("There is a difference between the wav file size"
                            " and the size of data that is written in the"
                            " header: "
                            << file_size << " != " << supposed_size);
                    return false;
                }

                return true;
            }
开发者ID:januswel,项目名称:avsutil,代码行数:19,代码来源:wav.hpp


示例13: write_json_internal

 void write_json_internal(std::basic_ostream<typename Ptree::char_type> &stream, 
                          const Ptree &pt,
                          const std::string &filename)
 {
     if (!verify_json(pt, 0))
         throw json_parser_error("ptree contains data that cannot be represented in JSON format", filename, 0);
     write_json_helper(stream, pt, 0);
     stream << std::endl;
     if (!stream.good())
         throw json_parser_error("write error", filename, 0);
 }
开发者ID:craton-,项目名称:php_mapnik,代码行数:11,代码来源:json_parser_write.hpp


示例14: write_json_internal

 void write_json_internal(std::basic_ostream<typename Ptree::key_type::value_type> &stream, 
                          const Ptree &pt,
                          const std::string &filename,
                          bool pretty)
 {
     if (!verify_json(pt, 0))
         BOOST_PROPERTY_TREE_THROW(json_parser_error("ptree contains data that cannot be represented in JSON format", filename, 0));
     write_json_helper(stream, pt, 0, pretty);
     stream << std::endl;
     if (!stream.good())
         BOOST_PROPERTY_TREE_THROW(json_parser_error("write error", filename, 0));
 }
开发者ID:Chang-Liu-0520,项目名称:dealii,代码行数:12,代码来源:json_parser_write.hpp


示例15: binary_oarchive_impl

 binary_oarchive_impl(
     std::basic_ostream<Elem, Tr> & os, 
     unsigned int flags
 ) :
     basic_binary_oprimitive<Archive, Elem, Tr>(
         * os.rdbuf(), 
         0 != (flags & no_codecvt)
     ),
     basic_binary_oarchive<Archive>(flags)
 {
     init(flags);
 }
开发者ID:12307,项目名称:EasyDarwin,代码行数:12,代码来源:binary_oarchive_impl.hpp


示例16: hex_dump

	inline void hex_dump(const void* aData, std::size_t aLength, std::basic_ostream<Elem, Traits>& aStream, std::size_t aWidth = 16)
	{
		const char* const start = static_cast<const char*>(aData);
		const char* const end = start + aLength;
		const char* line = start;
		while (line != end)
		{
			aStream.width(4);
			aStream.fill('0');
			aStream << std::hex << line - start << " : ";
			std::size_t lineLength = std::min(aWidth, static_cast<std::size_t>(end - line));
			for (std::size_t pass = 1; pass <= 2; ++pass)
			{	
				for (const char* next = line; next != end && next != line + aWidth; ++next)
				{
					char ch = *next;
					switch(pass)
					{
					case 1:
						aStream << (ch < 32 ? '.' : ch);
						break;
					case 2:
						if (next != line)
							aStream << " ";
						aStream.width(2);
						aStream.fill('0');
						aStream << std::hex << std::uppercase << static_cast<int>(static_cast<unsigned char>(ch));
						break;
					}
				}
				if (pass == 1 && lineLength != aWidth)
					aStream << std::string(aWidth - lineLength, ' ');
				aStream << " ";
			}
			aStream << std::endl;
			line = line + lineLength;
		}
	}
开发者ID:FlibbleMr,项目名称:neolib,代码行数:38,代码来源:hexdump.hpp


示例17: escape_char

 void escape_char(std::basic_ostream<Char, Traits> &os, Char c, Char delim) {
   const char escape = '\\';
   if(c < 32 || c == 0x7f) {
     os << escape;
     switch(c) {
     case '\0': os << os.widen('0'); break;
     case '\a': os << os.widen('a'); break;
     case '\b': os << os.widen('b'); break;
     case '\f': os << os.widen('f'); break;
     case '\n': os << os.widen('n'); break;
     case '\r': os << os.widen('r'); break;
     case '\t': os << os.widen('t'); break;
     case '\v': os << os.widen('v'); break;
     default:   os << os.widen('x') << static_cast<unsigned long>(c);
     }
   }
   else if(c == delim || c == escape) {
     os << escape << c;
   }
   else {
     os << c;
   }
 }
开发者ID:Redchards,项目名称:ImprovedEnum,代码行数:23,代码来源:string.hpp


示例18: handle_width

inline bool handle_width(std::basic_ostream<CharT, Traits>& o, const T& t) {
    std::streamsize width = o.width();
    if(width == 0) return false;

    std::basic_ostringstream<CharT, Traits> ss;

    ss.copyfmt(o);
    ss.tie(0);
    ss.width(0);

    ss << t;
    o << ss.str();

    return true;
}
开发者ID:CasparCG,项目名称:Client,代码行数:15,代码来源:tuple_io.hpp


示例19: 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


示例20: 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类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ std::bitset类代码示例发布时间:2022-06-01
下一篇:
C++ shell::Pointer类代码示例发布时间:2022-06-01
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap