C++ std::stringstream类
Posted Dontla
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C++ std::stringstream类相关的知识,希望对你有一定的参考价值。
文章目录
cppman std::stringstream
std::stringstream(3) C++ Programmer's Manual std::stringstream(3)
NAME
std::stringstream - Input/output string stream //输入/输出字符串流
TYPE
class
SYNOPSIS
#include <sstream>
typedef basic_stringstream<char> stringstream;
DESCRIPTION
o ios_base
o ios
o istreamostream
o iostream
o stringstream
Stream class to operate on strings.
Objects of this class use a string buffer that contains a sequence of characters. This sequence of characters can be accessed directly as a string object, using member str.
Characters can be inserted and/or extracted from the stream using any operation allowed on both input and output streams.
This is an instantiation of basic_stringstream with the following template parameters:
//Stream 类对字符串进行操作。
//此类的对象使用包含字符序列的字符串缓冲区。
//这个字符序列可以作为字符串对象直接访问,使用成员 str。
//可以使用输入和输出流上允许的任何操作从流中插入和/或提取字符。
//这是具有以下模板参数的 basic_stringstream 的实例化:
+-------------------+----------------------------------------------------------------------------------------------------------------------------------------+----------------------------------+
|template parameter | definition | comments |
+-------------------+----------------------------------------------------------------------------------------------------------------------------------------+----------------------------------+
|charT | char | Aliased as member char_type |
+-------------------+----------------------------------------------------------------------------------------------------------------------------------------+----------------------------------+
|traits | char_traits<char> | Aliased as member traits_type |
+-------------------+----------------------------------------------------------------------------------------------------------------------------------------+----------------------------------+
|Alloc | allocator<char> | Aliased as member allocator_type |
+-------------------+----------------------------------------------------------------------------------------------------------------------------------------+----------------------------------+
Apart from the internal string buffer, objects of these classes keep a set of internal fields inherited from ios_base, ios and istream:
+-----------+-------------------+-------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
| | field | member functions | description |
+-----------+-------------------+-------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
| | format flags | flagssetf | A set of internal flags that affect how certain input/output operations are interpreted or generated. See member type fmtflags. |
| | | unsetf | |
| +-------------------+-------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
| | field width | width | Width of the next formatted element to insert. |
|Formatting +-------------------+-------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
| | display precision | precision | Decimal precision for the next floating-point value inserted. |
| +-------------------+-------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
| | locale | getlocimbue | The locale object used by the function for formatted input/output operations affected by localization properties. |
| +-------------------+-------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
| | fill character | fill | Character to pad a formatted field up to the field width (width). |
+-----------+-------------------+-------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
| | error state | rdstatesetstate | The current error state of the stream. Individual values may be obtained by calling good, eof, fail and bad. |
|State | | clear | See member type iostate. |
| +-------------------+-------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
| | exception mask | exceptions | The state flags for which a failure exception is thrown. See member type iostate. |
+-----------+-------------------+-------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
| | callback stack | register_callback | Stack of pointers to functions that are called when certain events occur. |
| +-------------------+-------------------+----------------------------------------------------------------------------------------------------以上是关于C++ std::stringstream类的主要内容,如果未能解决你的问题,请参考以下文章
为什么我无法从std :: stringstream二进制流中获得完全精度(double,float)
为啥 std::stringstream 在静态内联时不能默认构造?
std::stringstream 可以设置失败/坏位的方式?
将 std::string 转换回使用 std::stringstream << cv::Mat 生成的 cv::Mat