c++11 standard template (STL) (std::basic_stringstream) (1)

Defined in the header file <sstream>
template<

    class CharT,
    class Traits = std::char_traits<CharT>

> class basic_stringstream;
(until C++11)
template<

    class CharT,
    class Traits = std::char_traits<CharT>,
    class Allocator = std::allocator<CharT>

> class basic_stringstream;
(since C++11)

Class template std::basic_stringstreamImplements input and output operations on string-based streams. It equivalently stores an instance of std::basic_string and performs input and output operations on it.

At a low level, this class actually wraps the raw string device of std::basic_stringbuf into the high-level interface of std::basic_iostream. Provides std::basic_stringbufa complete interface to exclusive members.

Two specializations are also defined for common character types:

type definition
stringstream basic_stringstream<char>
wstringstream basic_stringstream<wchar_t>

 

member type

member type definition
char_type CharT
traits_type Traits ; if Traits::char_typenot CharTthe program is ill-formed.
int_type Traits::int_type
pos_type Traits::pos_type
off_type Traits::off_type
allocator_type Allocator (since C++11)

member function

(Constructor)

Constructs a string stream
(public member function)

operator=

(C++11)

move string stream
(public member function)

swap

(C++11)

Swaps two string streams
(public member function)

rdbuf

Returns the underlying unhandled string device object
(public member function)
string manipulation

str

Get or set the content of the underlying string device object
(public member function)

non-member function

std::swap(std::basic_istringstream)

(C++11)

specialization of the std::swap algorithm
(function template)

 

Inherited from std::basic_istream

member function

formatted input

operator>>

Extract formatted data
( std::basic_istream<CharT,Traits>public member function of
plain input

get

Read and take away (remove like a pointer to move to the next element) a character from the stream
( std::basic_istream<CharT,Traits>public member function)

peek

Reads but does not take (does not remove like pointer does not move) a character
( std::basic_istream<CharT,Traits>public member function of)

rage

Undo the character just taken (removed, similar to a pointer back one position) in the stream
( std::basic_istream<CharT,Traits>public member function)

putback

Returns a character to the input stream
( std::basic_istream<CharT,Traits>public member function of)

getline

Read and remove characters until the given character is found
( std::basic_istream<CharT,Traits>public member function of)

ignore

reads and fetches and discards characters until the given character is found
( std::basic_istream<CharT,Traits>public member function of)

read

Read and take a block of characters
( std::basic_istream<CharT,Traits>public member function)

readsome

读并取走已经可用的字符块
(std::basic_istream<CharT,Traits> 的公开成员函数)

gcount

返回上次无格式输出操作所取走的字符数量
(std::basic_istream<CharT,Traits> 的公开成员函数)
寻位

tellg

返回输入位置指示器
(std::basic_istream<CharT,Traits> 的公开成员函数)

seekg

设置输入位置指示器
(std::basic_istream<CharT,Traits> 的公开成员函数)
杂项

sync

与底层存储设备同步
(std::basic_istream<CharT,Traits> 的公开成员函数)

成员类

sentry

实现为输出操作准备流的基本逻辑
(std::basic_istream<CharT,Traits> 的公开成员类)

继承自 std::basic_ostream

成员函数

有格式输出

operator<<

插入带格式数据
(std::basic_ostream<CharT,Traits> 的公开成员函数)
无格式输出

put

插入字符
(std::basic_ostream<CharT,Traits> 的公开成员函数)

write

插入字符块
(std::basic_ostream<CharT,Traits> 的公开成员函数)
寻位

tellp

返回输出位置指示器
(std::basic_ostream<CharT,Traits> 的公开成员函数)

seekp

设置输出位置指示器
(std::basic_ostream<CharT,Traits> 的公开成员函数)
杂项

flush

与底层存储设备同步
(std::basic_ostream<CharT,Traits> 的公开成员函数)

成员类

sentry

为输出操作实现流准备的基本逻辑
(std::basic_ostream<CharT,Traits> 的公开成员类)

 

继承自 std::basic_ios

成员类型

成员类型 定义
char_type CharT
traits_type Traits
int_type Traits::int_type
pos_type Traits::pos_type
off_type Traits::off_type

成员函数

状态函数

good

检查是否没有发生错误,例如是否可执行I/O操作
(std::basic_ios<CharT,Traits> 的公开成员函数)

eof

检查是否到达了文件末尾
(std::basic_ios<CharT,Traits> 的公开成员函数)

fail

检查是否发生了可恢复的错误
(std::basic_ios<CharT,Traits> 的公开成员函数)

bad

检查是否已发生不可恢复的错误
(std::basic_ios<CharT,Traits> 的公开成员函数)

operator!

检查是否有错误发生(fail() 的同义词)
(std::basic_ios<CharT,Traits> 的公开成员函数)

operator void*operator bool

(C++11 前)(C++11 起)

检查是否没有发生错误(!fail()的同义词)
(std::basic_ios<CharT,Traits> 的公开成员函数)

rdstate

返回状态标志
(std::basic_ios<CharT,Traits> 的公开成员函数)

setstate

设置状态标志
(std::basic_ios<CharT,Traits> 的公开成员函数)

clear

修改状态标志
(std::basic_ios<CharT,Traits> 的公开成员函数)
格式化

copyfmt

复制格式化信息
(std::basic_ios<CharT,Traits> 的公开成员函数)

fill

管理填充字符
(std::basic_ios<CharT,Traits> 的公开成员函数)
杂项

exceptions

管理异常掩码
(std::basic_ios<CharT,Traits> 的公开成员函数)

imbue

设置本地环境
(std::basic_ios<CharT,Traits> 的公开成员函数)

rdbuf

管理相关的流缓冲区
(std::basic_ios<CharT,Traits> 的公开成员函数)

tie

管理绑定的流
(std::basic_ios<CharT,Traits> 的公开成员函数)

narrow

窄化字符
(std::basic_ios<CharT,Traits> 的公开成员函数)

widen

拓宽字符
(std::basic_ios<CharT,Traits> 的公开成员函数)

继承自 std::ios_base

成员函数

格式化

flags

管理格式标志
(std::ios_base 的公开成员函数)

setf

设置特定格式标志
(std::ios_base 的公开成员函数)

unsetf

清除特定格式的标志
(std::ios_base 的公开成员函数)

precision

管理浮点操作的精度
(std::ios_base 的公开成员函数)

width

管理域的宽度
(std::ios_base 的公开成员函数)
本地环境

imbue

设置本地环境
(std::ios_base 的公开成员函数)

getloc

返回当前本地环境
(std::ios_base 的公开成员函数)
内部可扩展数组

xalloc

[静态]

返回能安全用作 pword() 和 iword() 下标的程序范围内独有的整数
(std::ios_base 的公开静态成员函数)

iword

如果有必要的话,调整私有存储的大小,并且访问位于提供的下标的long元素
(std::ios_base 的公开成员函数)

pword

若需要则重置私有存储的大小,并访问位于指定下标的 void* 元素
(std::ios_base 的公开成员函数)
杂项

register_callback

注册事件回调函数
(std::ios_base 的公开成员函数)

sync_with_stdio

[静态]

设置C++和C的IO库是否可以互操作
(std::ios_base 的公开静态成员函数)
成员类

failure

流异常
(std::ios_base 的公开成员类)

Init

初始化标准流对象
(std::ios_base 的公开成员类)

成员类型和常量

类型 解释

openmode

流打开模式类型

亦定义下列常量:

常量 解释
app 每次写入前寻位到流结尾
binary 以二进制模式打开
in 为读打开
out 为写打开
trunc 在打开时舍弃流的内容
ate 打开后立即寻位到流结尾
(typedef)

fmtflags

格式化标志类型

亦定义下列常量:

常量 解释
dec 为整数 I/O 使用十进制底:见 std::dec
oct 为整数 I/O 使用八进制底:见 std::oct
hex 为整数 I/O 使用十六进制底:见 std::hex
basefield dec|oct|hex 。适用于掩码运算
left 左校正(添加填充字符到右):见 std::left
right 右校正(添加填充字符到左):见 std::right
internal 内部校正(添加填充字符到内部选定点):见 std::internal
adjustfield left|right|internal 。适用于掩码运算
scientific 用科学记数法生成浮点类型,或若与 fixed 组合则用十六进制记法:见 std::scientific
fixed 用定点记法生成浮点类型,或若与 scientific 组合则用十六进制记法:见 std::fixed
floatfield scientific|fixed 。适用于掩码运算
boolalpha 以字母数字格式插入并释出 bool 类型:见 std::boolalpha
showbase 生成为整数输出指示数字基底的前缀,货币 I/O 中要求现金指示器:见 std::showbase
showpoint 无条件为浮点数输出生成小数点字符:见 std::showpoint
showpos 为非负数值输出生成 + 字符,见 std::showpos
skipws 在具体输入操作前跳过前导空白符:见 std::skipws
unitbuf 在每次输出操作后冲入输出:见 std::unitbuf
uppercase 在具体输出的输出操作中以大写等价替换小写字符:见 std::uppercase
(typedef)

iostate

流状态类型

亦定义下列常量:

常量 解释
goodbit 无错误
badbit 不可恢复的流错误
failbit 输入/输出操作失败(格式化或提取错误)
eofbit 关联的输出序列已抵达文件尾
(typedef)

seekdir

寻位方向类型

亦定义下列常量:

常量 解释
beg 流的开始
end 流的结尾
cur 流位置指示器的当前位置
(typedef)

event

指定事件类型
(枚举)

event_callback

回调函数类型
(typedef)

 

Guess you like

Origin blog.csdn.net/qq_40788199/article/details/132522169