本文整理汇总了C++中std::basic_ostream::write方法的典型用法代码示例。如果您正苦于以下问题:C++ basic_ostream::write方法的具体用法?C++ basic_ostream::write怎么用?C++ basic_ostream::write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::basic_ostream
的用法示例。
在下文中一共展示了basic_ostream::write方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
示例2: write
void write(const CharT* s, size_t length)
{
size_t diff = end_buffer_ - p_;
if (diff >= length)
{
std::memcpy(p_, s, length*sizeof(CharT));
p_ += length;
}
else
{
os_->write(begin_buffer_, (p_ - begin_buffer_));
os_->write(s, length);
p_ = begin_buffer_;
}
}
示例3: insert_aligned
void insert_aligned(std::basic_ostream<charT, traits>& os, const basic_string_ref<charT,traits>& str) {
const std::size_t size = str.size();
const std::size_t alignment_size = static_cast< std::size_t >(os.width()) - size;
const bool align_left = (os.flags() & std::basic_ostream<charT, traits>::adjustfield) == std::basic_ostream<charT, traits>::left;
if (!align_left) {
detail::insert_fill_chars(os, alignment_size);
if (os.good())
os.write(str.data(), size);
}
else {
os.write(str.data(), size);
if (os.good())
detail::insert_fill_chars(os, alignment_size);
}
}
示例4: put
void put(CharT c)
{
if (p_ < end_buffer_)
{
*p_++ = c;
}
else
{
os_->write(begin_buffer_, (p_-begin_buffer_));
p_ = begin_buffer_;
*p_++ = c;
}
}
示例5: flush
void flush()
{
os_->write(begin_buffer_, (p_ - begin_buffer_));
p_ = begin_buffer_;
os_->flush();
}
示例6:
~buffered_ostream()
{
os_->write(begin_buffer_, (p_ - begin_buffer_));
os_->flush();
}