GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::basic_istringstream::basic_istringstream(3) C++ Standard Libary std::basic_istringstream::basic_istringstream(3)

std::basic_istringstream::basic_istringstream - std::basic_istringstream::basic_istringstream


basic_istringstream() (1) (since
: basic_istringstream(std::ios_base::in) { } C++11)
explicit basic_istringstream( std::ios_base::openmode mode = (until
std::ios_base::in ); C++11)
explicit basic_istringstream( std::ios_base::openmode mode ); (since
C++11)
explicit basic_istringstream( const
std::basic_string<CharT,Traits,Allocator>& str, (3)
std::ios_base::openmode mode = std::ios_base::in );
basic_istringstream( basic_istringstream&& other ); (4) (since
C++11)
basic_istringstream( std::ios_base::openmode mode, const (5) (since
Allocator& a ); C++20)
explicit basic_istringstream( (since
std::basic_string<CharT,Traits,Allocator>&& str, (6) C++20)
std::ios_base::openmode mode = std::ios_base::in );
template<class SAlloc>


basic_istringstream( const (2) (since
std::basic_string<CharT,Traits,SAlloc>& str, (7) C++20)
const Allocator& a )


: basic_istringstream(str, std::ios_base::in, a) { }
template<class SAlloc>


basic_istringstream( const (8) (since
std::basic_string<CharT,Traits,SAlloc>& str, C++20)


std::ios_base::openmode mode, const Allocator& a );
template<class SAlloc>


explicit basic_istringstream( const (9) (since
std::basic_string<CharT,Traits,SAlloc>& str, C++20)


std::ios_base::openmode mode = std::ios_base::in );


Constructs new string stream.


1) Default constructor. Constructs new underlying string device with the default
open mode
2) Constructs new underlying string device. The underlying basic_stringbuf object is
constructed as basic_stringbuf<Char,Traits,Allocator>(mode | std::ios_base::in).
3) Uses a copy of str as initial contents of the underlying string device. The
underlying basic_stringbuf object is constructed as
basic_stringbuf<Char,Traits,Allocator>(str, mode | std::ios_base::in).
4) Move constructor. Constructs the string stream with the state of other using move
semantics.
5) Constructs new underlying string device. The underlying basic_stringbuf object is
constructed as basic_stringbuf<Char,Traits,Allocator>(mode | std::ios_base::in, a).
6) Move-construct the contents of the underlying string device with str. The
underlying basic_stringbuf object is constructed as
basic_stringbuf<Char,Traits,Allocator>(std::move(str), mode | std::ios_base::in).
7) Constructs new underlying string device. The underlying basic_stringbuf object is
constructed as basic_stringbuf<Char,Traits,Allocator>(str, std::ios_base::in, a).
8) Constructs new underlying string device. The underlying basic_stringbuf object is
constructed as basic_stringbuf<Char,Traits,Allocator>(str, mode | std::ios_base::in,
a).
9) Constructs new underlying string device. The underlying basic_stringbuf object is
constructed as basic_stringbuf<Char,Traits,Allocator>(str, mode |
std::ios_base::in).


str - string to use as initial contents of the string stream
a - allocator used for allocating the contents of the string stream
specifies stream open mode. It is bitmask type, the following constants are
defined:


Constant Explanation
mode - app seek to the end of stream before each write
binary open in binary mode
in open for reading
out open for writing
trunc discard the contents of the stream when opening
ate seek to the end of stream immediately after open
other - another string stream to use as source


Construction of one-off basic_istringstream objects in a tight loop, such as when
used for string conversion, may be significantly more costly than calling str to
reuse the same object.

// Run this code


#include <iostream>
#include <sstream>
int main()
{
// default constructor (input/output stream)
std::stringstream buf1;
buf1 << 7;
int n = 0;
buf1 >> n;
std::cout << "buf1 = " << buf1.str() << " n = " << n << '\n';


// input stream
std::istringstream inbuf("-10");
inbuf >> n;
std::cout << "n = " << n << '\n';


// output stream in append mode (C++11)
std::ostringstream buf2("test", std::ios_base::ate);
buf2 << '1';
std::cout << buf2.str() << '\n';
}


buf1 = 7 n = 7
n = -10
test1


Defect reports


The following behavior-changing defect reports were applied retroactively to
previously published C++ standards.


DR Applied to Behavior as published Correct behavior
P0935R0 C++11 default constructor was explicit made implicit


str gets or sets the contents of underlying string device object
(public member function)
constructs a basic_stringbuf object
constructor (public member function of
std::basic_stringbuf<CharT,Traits,Allocator>)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.