本文整理汇总了C++中std::ostringstream::tellp方法的典型用法代码示例。如果您正苦于以下问题:C++ ostringstream::tellp方法的具体用法?C++ ostringstream::tellp怎么用?C++ ostringstream::tellp使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::ostringstream
的用法示例。
在下文中一共展示了ostringstream::tellp方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _print_double
/** Print a formatted double to the output stream.
*/
void _print_double(std::ostringstream& ss, size_t width, double value) {
if(long(value) == value) {
std::string sv = std::to_string(long(value));
if(sv.size() < width) {
_print_string(ss, width, sv);
return;
}
}
ss << ' ';
size_t start_pos = ss.tellp();
bool printed_normally = false;
{
std::ostringstream ss_buf;
ss_buf.width(width);
ss_buf << std::left << value;
if(size_t(ss_buf.tellp()) <= width) {
ss << ss_buf.str();
printed_normally = true;
}
}
if(!printed_normally) {
// Find a good precision with which to print this; loop until it
// breaks or we hit 4 decimal places.
size_t precision = 0;
for(;precision < 5; ++precision) {
std::ostringstream ss_buf;
ss_buf.width(width);
ss_buf << std::left << std::setprecision(precision) << value;
if(ss_buf.tellp() > long(width)) {
precision = (precision == 0) ? 0 : (precision - 1);
std::ostringstream ss_buf_2;
ss_buf_2.width(width);
ss_buf_2 << std::left << std::setprecision(precision) << value;
ss << ss_buf_2.str();
break;
}
}
}
// Add in padding as needed.
while(size_t(ss.tellp()) < start_pos + width)
ss << ' ';
ss << ' ' << '|';
}
示例2:
static inline void sd_write_aligned_blob(std::ostringstream &buf, void *b, int b_size,
const char *name)
{
sd_write_name(buf, name);
/* pad calculation MUST come after name is written */
size_t pad = align64(buf.tellp() + ((std::streamoff) 5l)) - (buf.tellp() + ((std::streamoff) 5l));
sd_write8(buf, SD_BLOB);
sd_write32(buf, b_size + pad);
buf.write(zeros, pad);
buf.write((const char *) b, b_size);
}
示例3: sendBuffer
Variant ClientBase::sendBuffer(char type, RequestID requestID, std::ostringstream &stream)
{
unsigned int size = (unsigned int)stream.tellp();
size -= sizeof(size);
stream.seekp(0);
stream.write((const char*)&size, sizeof(size));
RequestData rd;
rd.type = MessageType(type);
rd.id = requestID;
rd.data = stream.str();
if(asyncMode())
{
rd.writeCompletePtr.reset(new FutureResult);
bool empty = m_messageQueue.empty();
m_messageQueue.push(rd);
if(empty)
{
writeData(m_messageQueue.front().data);
}
return rd.writeCompletePtr;
}
else
{
writeData(rd.data);
}
return Variant();
}
示例4: to_binary
std::string to_binary(std::ostringstream &out, const T &t) {
out.clear();
out.seekp(0);
bf::fold(t, 0, app_item(out));
// because out.str() gives us the contents of the string buffer,
// not the contents written since clear() was called, we need to
// chop off any remaining garbage at the end.
std::string rv = out.str();
rv.resize(out.tellp());
return rv;
}
示例5: tell
size_t tell()
{
return stream.tellp();
}