314 lines
13 KiB
Markdown
314 lines
13 KiB
Markdown
[istringstream]
|
||
|
||
# 31 Input/output library [[input.output]](./#input.output)
|
||
|
||
## 31.8 String-based streams [[string.streams]](string.streams#istringstream)
|
||
|
||
### 31.8.3 Class template basic_istringstream [istringstream]
|
||
|
||
#### [31.8.3.1](#general) General [[istringstream.general]](istringstream.general)
|
||
|
||
[ð](#lib:basic_istringstream)
|
||
|
||
namespace std {template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT>>class basic_istringstream : public basic_istream<charT, traits> {public:using char_type = charT; using int_type = typename traits::int_type; using pos_type = typename traits::pos_type; using off_type = typename traits::off_type; using traits_type = traits; using allocator_type = Allocator; // [[istringstream.cons]](#cons "31.8.3.2 Constructors"), constructors basic_istringstream() : basic_istringstream(ios_base::in) {}explicit basic_istringstream(ios_base::openmode which); explicit basic_istringstream(const basic_string<charT, traits, Allocator>& s,
|
||
ios_base::openmode which = ios_base::in);
|
||
basic_istringstream(ios_base::openmode which, const Allocator& a); explicit basic_istringstream( basic_string<charT, traits, Allocator>&& s,
|
||
ios_base::openmode which = ios_base::in); template<class SAlloc> basic_istringstream(const basic_string<charT, traits, SAlloc>& s, const Allocator& a): basic_istringstream(s, ios_base::in, a) {}template<class SAlloc> basic_istringstream(const basic_string<charT, traits, SAlloc>& s,
|
||
ios_base::openmode which, const Allocator& a); template<class SAlloc>explicit basic_istringstream(const basic_string<charT, traits, SAlloc>& s,
|
||
ios_base::openmode which = ios_base::in); template<class T>explicit basic_istringstream(const T& t, ios_base::openmode which = ios_base::in); template<class T> basic_istringstream(const T& t, const Allocator& a); template<class T> basic_istringstream(const T& t, ios_base::openmode which, const Allocator& a);
|
||
basic_istringstream(const basic_istringstream&) = delete;
|
||
basic_istringstream(basic_istringstream&& rhs);
|
||
|
||
basic_istringstream& operator=(const basic_istringstream&) = delete;
|
||
basic_istringstream& operator=(basic_istringstream&& rhs); // [[istringstream.swap]](#swap "31.8.3.3 Swap"), swapvoid swap(basic_istringstream& rhs); // [[istringstream.members]](#members "31.8.3.4 Member functions"), members basic_stringbuf<charT, traits, Allocator>* rdbuf() const;
|
||
basic_string<charT, traits, Allocator> str() const &; template<class SAlloc> basic_string<charT,traits,SAlloc> str(const SAlloc& sa) const;
|
||
basic_string<charT, traits, Allocator> str() &&;
|
||
basic_string_view<charT, traits> view() const noexcept; void str(const basic_string<charT, traits, Allocator>& s); template<class SAlloc>void str(const basic_string<charT, traits, SAlloc>& s); void str(basic_string<charT, traits, Allocator>&& s); template<class T>void str(const T& t); private: basic_stringbuf<charT, traits, Allocator> *sb*; // *exposition only*};}
|
||
|
||
[1](#general-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8953)
|
||
|
||
The classbasic_istringstream<charT, traits, Allocator> supports reading objects of classbasic_string<charT, traits, Allocator>[.](#general-1.sentence-1)
|
||
|
||
It uses abasic_stringbuf<charT, traits, Allocator> object to control the associated storage[.](#general-1.sentence-2)
|
||
|
||
For the sake of exposition, the maintained data is presented here as:
|
||
|
||
- [(1.1)](#general-1.1)
|
||
|
||
*sb*, the stringbuf object[.](#general-1.sentence-3)
|
||
|
||
#### [31.8.3.2](#cons) Constructors [[istringstream.cons]](istringstream.cons)
|
||
|
||
[ð](#lib:basic_istringstream,constructor)
|
||
|
||
`explicit basic_istringstream(ios_base::openmode which);
|
||
`
|
||
|
||
[1](#cons-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8975)
|
||
|
||
*Effects*: Initializes the base class withbasic_istream<charT, traits>(addressof(*sb*)) ([[istream]](istream "31.7.5.2 Class template basic_istream"))
|
||
and *sb* withbasic_stringbuf<charT, traits, Allocator>(which | ios_base::in) ([[stringbuf.cons]](stringbuf.cons "31.8.2.2 Constructors"))[.](#cons-1.sentence-1)
|
||
|
||
[ð](#lib:basic_istringstream,constructor_)
|
||
|
||
`explicit basic_istringstream(
|
||
const basic_string<charT, traits, Allocator>& s,
|
||
ios_base::openmode which = ios_base::in);
|
||
`
|
||
|
||
[2](#cons-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L8991)
|
||
|
||
*Effects*: Initializes the base class withbasic_istream<charT, traits>(addressof(*sb*)) ([[istream]](istream "31.7.5.2 Class template basic_istream"))
|
||
and *sb* withbasic_stringbuf<charT, traits, Allocator>(s, which | ios_base::in)
|
||
([[stringbuf.cons]](stringbuf.cons "31.8.2.2 Constructors"))[.](#cons-2.sentence-1)
|
||
|
||
[ð](#lib:basic_istringstream,constructor__)
|
||
|
||
`basic_istringstream(ios_base::openmode which, const Allocator& a);
|
||
`
|
||
|
||
[3](#cons-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9005)
|
||
|
||
*Effects*: Initializes the base class withbasic_istream<charT, traits>(addressof(*sb*)) ([[istream]](istream "31.7.5.2 Class template basic_istream"))
|
||
and *sb* withbasic_stringbuf<charT, traits, Allocator>(which | ios_base::in, a) ([[stringbuf.cons]](stringbuf.cons "31.8.2.2 Constructors"))[.](#cons-3.sentence-1)
|
||
|
||
[ð](#lib:basic_istringstream,constructor___)
|
||
|
||
`explicit basic_istringstream(
|
||
basic_string<charT, traits, Allocator>&& s,
|
||
ios_base::openmode which = ios_base::in);
|
||
`
|
||
|
||
[4](#cons-4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9021)
|
||
|
||
*Effects*: Initializes the base class withbasic_istream<charT, traits>(addressof(*sb*)) ([[istream]](istream "31.7.5.2 Class template basic_istream"))
|
||
and *sb* withbasic_stringbuf<charT, traits, Allocator>(std::move(s), which | ios_base::in) ([[stringbuf.cons]](stringbuf.cons "31.8.2.2 Constructors"))[.](#cons-4.sentence-1)
|
||
|
||
[ð](#lib:basic_istringstream,constructor____)
|
||
|
||
`template<class SAlloc>
|
||
basic_istringstream(
|
||
const basic_string<charT, traits, SAlloc>& s,
|
||
ios_base::openmode which, const Allocator& a);
|
||
`
|
||
|
||
[5](#cons-5)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9038)
|
||
|
||
*Effects*: Initializes the base class withbasic_istream<charT, traits>(addressof(*sb*)) ([[istream]](istream "31.7.5.2 Class template basic_istream"))
|
||
and *sb* withbasic_stringbuf<charT, traits, Allocator>(s, which | ios_base::in, a)
|
||
([[stringbuf.cons]](stringbuf.cons "31.8.2.2 Constructors"))[.](#cons-5.sentence-1)
|
||
|
||
[ð](#lib:basic_istringstream,constructor_____)
|
||
|
||
`template<class SAlloc>
|
||
explicit basic_istringstream(
|
||
const basic_string<charT, traits, SAlloc>& s,
|
||
ios_base::openmode which = ios_base::in);
|
||
`
|
||
|
||
[6](#cons-6)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9055)
|
||
|
||
*Constraints*: is_same_v<SAlloc, Allocator> is false[.](#cons-6.sentence-1)
|
||
|
||
[7](#cons-7)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9059)
|
||
|
||
*Effects*: Initializes the base class withbasic_istream<charT, traits>(addressof(*sb*)) ([[istream]](istream "31.7.5.2 Class template basic_istream"))
|
||
and *sb* withbasic_stringbuf<charT, traits, Allocator>(s, which | ios_base::in) ([[stringbuf.cons]](stringbuf.cons "31.8.2.2 Constructors"))[.](#cons-7.sentence-1)
|
||
|
||
[ð](#lib:basic_istringstream,constructor______)
|
||
|
||
`template<class T>
|
||
explicit basic_istringstream(const T& t, ios_base::openmode which = ios_base::in);
|
||
template<class T>
|
||
basic_istringstream(const T& t, const Allocator& a);
|
||
template<class T>
|
||
basic_istringstream(const T& t, ios_base::openmode which, const Allocator& a);
|
||
`
|
||
|
||
[8](#cons-8)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9078)
|
||
|
||
Let which be ios_base::in for the overload with no parameter which, anda be Allocator() for the overload with no parameter a[.](#cons-8.sentence-1)
|
||
|
||
[9](#cons-9)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9083)
|
||
|
||
*Constraints*: is_convertible_v<const T&, basic_string_view<charT, traits>> is true[.](#cons-9.sentence-1)
|
||
|
||
[10](#cons-10)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9088)
|
||
|
||
*Effects*: Initializes the base class with addressof(*sb*), and
|
||
direct-non-list-initializes *sb* with t, which | ios_base::in, a[.](#cons-10.sentence-1)
|
||
|
||
[ð](#lib:basic_istringstream,constructor_______)
|
||
|
||
`basic_istringstream(basic_istringstream&& rhs);
|
||
`
|
||
|
||
[11](#cons-11)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9100)
|
||
|
||
*Effects*: Move constructs from the rvalue rhs[.](#cons-11.sentence-1)
|
||
|
||
This
|
||
is accomplished by move constructing the base class, and the containedbasic_stringbuf[.](#cons-11.sentence-2)
|
||
|
||
Then calls basic_istream<charT, traits>::set_rdbuf(addressof(*sb*)) to install the contained basic_stringbuf[.](#cons-11.sentence-3)
|
||
|
||
#### [31.8.3.3](#swap) Swap [[istringstream.swap]](istringstream.swap)
|
||
|
||
[ð](#lib:swap,basic_istringstream)
|
||
|
||
`void swap(basic_istringstream& rhs);
|
||
`
|
||
|
||
[1](#swap-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9117)
|
||
|
||
*Effects*: Equivalent to:basic_istream<charT, traits>::swap(rhs);*sb*.swap(rhs.*sb*);
|
||
|
||
[ð](#lib:swap,basic_istringstream_)
|
||
|
||
`template<class charT, class traits, class Allocator>
|
||
void swap(basic_istringstream<charT, traits, Allocator>& x,
|
||
basic_istringstream<charT, traits, Allocator>& y);
|
||
`
|
||
|
||
[2](#swap-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9135)
|
||
|
||
*Effects*: Equivalent to x.swap(y)[.](#swap-2.sentence-1)
|
||
|
||
#### [31.8.3.4](#members) Member functions [[istringstream.members]](istringstream.members)
|
||
|
||
[ð](#lib:rdbuf,basic_istringstream)
|
||
|
||
`basic_stringbuf<charT, traits, Allocator>* rdbuf() const;
|
||
`
|
||
|
||
[1](#members-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9148)
|
||
|
||
*Returns*: const_cast<basic_stringbuf<charT, traits, Allocator>*>(addressof(*sb*))[.](#members-1.sentence-1)
|
||
|
||
[ð](#lib:str,basic_istringstream)
|
||
|
||
`basic_string<charT, traits, Allocator> str() const &;
|
||
`
|
||
|
||
[2](#members-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9159)
|
||
|
||
*Effects*: Equivalent to: return rdbuf()->str();
|
||
|
||
[ð](#lib:str,basic_istringstream_)
|
||
|
||
`template<class SAlloc>
|
||
basic_string<charT,traits,SAlloc> str(const SAlloc& sa) const;
|
||
`
|
||
|
||
[3](#members-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9171)
|
||
|
||
*Effects*: Equivalent to: return rdbuf()->str(sa);
|
||
|
||
[ð](#lib:str,basic_istringstream__)
|
||
|
||
`basic_string<charT,traits,Allocator> str() &&;
|
||
`
|
||
|
||
[4](#members-4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9182)
|
||
|
||
*Effects*: Equivalent to: return std::move(*rdbuf()).str();
|
||
|
||
[ð](#lib:view,basic_istringstream)
|
||
|
||
`basic_string_view<charT, traits> view() const noexcept;
|
||
`
|
||
|
||
[5](#members-5)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9193)
|
||
|
||
*Effects*: Equivalent to: return rdbuf()->view();
|
||
|
||
[ð](#lib:str,basic_istringstream___)
|
||
|
||
`void str(const basic_string<charT, traits, Allocator>& s);
|
||
`
|
||
|
||
[6](#members-6)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9204)
|
||
|
||
*Effects*: Equivalent to: rdbuf()->str(s);
|
||
|
||
[ð](#lib:str,basic_istringstream____)
|
||
|
||
`template<class SAlloc>
|
||
void str(const basic_string<charT, traits, SAlloc>& s);
|
||
`
|
||
|
||
[7](#members-7)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9216)
|
||
|
||
*Effects*: Equivalent to: rdbuf()->str(s);
|
||
|
||
[ð](#lib:str,basic_istringstream_____)
|
||
|
||
`void str(basic_string<charT, traits, Allocator>&& s);
|
||
`
|
||
|
||
[8](#members-8)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9227)
|
||
|
||
*Effects*: Equivalent to: rdbuf()->str(std::move(s));
|
||
|
||
[ð](#lib:str,basic_istringstream______)
|
||
|
||
`template<class T>
|
||
void str(const T& t);
|
||
`
|
||
|
||
[9](#members-9)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9239)
|
||
|
||
*Constraints*: is_convertible_v<const T&, basic_string_view<charT, traits>> is true[.](#members-9.sentence-1)
|
||
|
||
[10](#members-10)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L9244)
|
||
|
||
*Effects*: Equivalent to: rdbuf()->str(t);
|