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