当前位置: 首页>>代码示例>>C++>>正文


C++ ostringstream::tellp方法代码示例

本文整理汇总了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 << ' ' << '|';
}
开发者ID:Hannah1999,项目名称:Dato-Core,代码行数:59,代码来源:table_element_printers.cpp

示例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);
}
开发者ID:crossbuild,项目名称:apparmor,代码行数:11,代码来源:parser_interface.c

示例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();
}
开发者ID:xandr84,项目名称:RPC,代码行数:29,代码来源:transport.cpp

示例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;
}
开发者ID:zerebubuth,项目名称:planet-dump-ng,代码行数:11,代码来源:extract_kv.cpp

示例5: tell

 size_t tell()
 {
     return stream.tellp();
 }
开发者ID:macressler,项目名称:anaconda,代码行数:4,代码来源:stdiofile.cpp


注:本文中的std::ostringstream::tellp方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。