首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::basic_ostream::write

basic_ostream& write( const char_type* s, std::streamsize count );

?

?

表现为UnformattedOutputFunction.在构造和检查哨兵对象之后,输出字符数组中第一个元素指向的连续位置的字符。s将字符插入到输出序列中,直到出现下列情况之一:

  • 一点儿没错count插入字符
  • 插入输出序列失败%28,在这种情况下setstate(badbit)称为%29

参数

s

-

pointer to the character string to write

count

-

number of characters to write

返回值

*this...

注记

此函数不会对类型重载。signed charunsigned char,与格式化的运算符<<

此外,与格式化的输出函数不同,此函数不设置failbit在失败的时候。

例外

如果在输出期间发生异常,则exceptions() & badbit != 0重新抛出那个异常。

如果输出失败,并且exceptions() & badbit != 0,抛ios_base::failure...

此函数可用于输出对象表示,即二进制输出。

二次

代码语言:javascript
复制
#include <iostream>
 
int main()
{
    int n = 0x41424344;
    std::cout.write(reinterpret_cast<char*>(&n), sizeof n) << '\n';
 
    char c[]="This is sample text.";
    std::cout.write(c,4)<<'\n';
}

二次

可能的产出:

二次

代码语言:javascript
复制
DCBA
This

二次

另见

operator<<(std::basic_ostream)

inserts character data (function template)

put

inserts a character (public member function)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com