本文整理汇总了C++中std::basic_ostream类的典型用法代码示例。如果您正苦于以下问题:C++ basic_ostream类的具体用法?C++ basic_ostream怎么用?C++ basic_ostream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了basic_ostream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
示例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
);
}
示例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('}');
}
}
示例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);
}
示例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 << '"';
}
示例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 << '"';
}
示例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 );
}
示例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);
}
示例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)
{}
示例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);
}
示例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));
}
示例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;
}
示例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);
}
示例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));
}
示例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);
}