本文整理汇总了C++中std::ostringstream::put方法的典型用法代码示例。如果您正苦于以下问题:C++ ostringstream::put方法的具体用法?C++ ostringstream::put怎么用?C++ ostringstream::put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::ostringstream
的用法示例。
在下文中一共展示了ostringstream::put方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dumpString
static void dumpString(std::ostringstream& os, const char *s) {
os.put('"');
while (*s) {
char c = *s++;
switch (c) {
case '\b':
os << "\\b";
break;
case '\f':
os << "\\f";
break;
case '\n':
os << "\\n";
break;
case '\r':
os << "\\r";
break;
case '\t':
os << "\\t";
break;
case '\\':
os << "\\\\";
break;
case '"':
os << "\\\"";
break;
default:
os.put(c);
}
}
os << s << "\"";
}
示例2: dumpValue
static void dumpValue(std::ostringstream& os, const JsonValue& o, int shiftWidth, const std::string& linefeed = "", int indent = 0) {
switch (o.getTag()) {
case JSON_NUMBER:
char buffer[32];
sprintf(buffer, "%f", o.toNumber());
os << buffer;
break;
case JSON_TRUE:
os << "true";
break;
case JSON_FALSE:
os << "false";
break;
case JSON_STRING:
dumpString(os, o.toString());
break;
case JSON_ARRAY:
// It is not necessary to use o.toNode() to check if an array or object
// is empty before iterating over its members, we do it here to allow
// nicer pretty printing.
if (!o.toNode()) {
os << "[]";
break;
}
os << "[" << linefeed;
for (auto i : o) {
if (shiftWidth > 0)
os << std::setw(indent + shiftWidth) << " " << std::setw(0);
dumpValue(os, i->value, shiftWidth, linefeed, indent + shiftWidth);
if (i->next)
os << ",";
os << linefeed;
}
if (indent > 0)
os << std::setw(indent) << " " << std::setw(0);
os.put(']');
break;
case JSON_OBJECT:
if (!o.toNode()) {
os << "{}";
break;
}
os << "{" << linefeed;
for (auto i : o) {
if (shiftWidth > 0)
os << std::setw(indent + shiftWidth) << " " << std::setw(0);
dumpString(os, i->key);
os << ":";
dumpValue(os, i->value, shiftWidth, linefeed, indent + shiftWidth);
if (i->next)
os << ",";
os << linefeed;
}
if (indent > 0)
os << std::setw(indent) << " " << std::setw(0);
os.put('}');
break;
case JSON_NULL:
os << "null";
break;
}
}