CARVIEW |
Select Language
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Sat, 26 Jul 2025 15:39:02 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Location: /reference/istream/basic_istream/operator-free/
HTTP/1.1 200 OK
Server: nginx
Date: Sat, 26 Jul 2025 15:39:02 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
ETag: W/"92b3-8tO7v8dzUCu69p/NomLt69YPAi0"
Content-Encoding: gzip
This operator (
Internally, the function accesses the input sequence of is by first constructing a sentry with noskipws set to
Notice that if this function extracts the last character of a stream when extracting a single character (1), it does not set its eofbit flag, but attempting to extract beyond it does.
Calling this function does not alter the value returned by gcount on is.
The extracted value or sequence is not returned, but directly stored in the variable passed as argument.
Errors are signaled by modifying the internal state flags:
Multiple flags may be set by a single operation.
If the operation sets an internal state flag that was registered with is's member exceptions, the function throws an exception of is's failure member type.
This example demonstrates the use of some of the overloaded operator>> functions shown above using the standard basic_istream object cin.
Modifies is.
Concurrent access to the same stream object may cause data races, except for the standard stream objects cin and wcin when these are synchronized with stdio (in this case, no data races are initiated, although no guarantees are given on the order in which extracted characters are attributed to threads).
It throws an exception of member type failure if the resulting error state flag for is is not goodbit and member exceptions was set to throw for that state in is.
Any exception thrown by an internal operation is caught and handled by the function, setting is's badbit flag. If badbit was set on the last call to exceptions for is, the function rethrows the caught exception.
Reference
C library:
- <cassert> (assert.h)
- <cctype> (ctype.h)
- <cerrno> (errno.h)
-
<cfenv> (fenv.h)C++11
- <cfloat> (float.h)
-
<cinttypes> (inttypes.h)C++11
- <ciso646> (iso646.h)
- <climits> (limits.h)
- <clocale> (locale.h)
- <cmath> (math.h)
- <csetjmp> (setjmp.h)
- <csignal> (signal.h)
- <cstdarg> (stdarg.h)
-
<cstdbool> (stdbool.h)C++11
- <cstddef> (stddef.h)
-
<cstdint> (stdint.h)C++11
- <cstdio> (stdio.h)
- <cstdlib> (stdlib.h)
- <cstring> (string.h)
-
<ctgmath> (tgmath.h)C++11
- <ctime> (time.h)
-
<cuchar> (uchar.h)C++11
- <cwchar> (wchar.h)
- <cwctype> (wctype.h)
Containers:
-
<array>C++11
- <deque>
-
<forward_list>C++11
- <list>
- <map>
- <queue>
- <set>
- <stack>
-
<unordered_map>C++11
-
<unordered_set>C++11
- <vector>
-
Input/Output:
Multi-threading:
-
<atomic>C++11
-
<condition_variable>C++11
-
<future>C++11
-
<mutex>C++11
-
<thread>C++11
-
Other:
- <algorithm>
- <bitset>
-
<chrono>C++11
-
<codecvt>C++11
- <complex>
- <exception>
- <functional>
-
<initializer_list>C++11
- <iterator>
- <limits>
- <locale>
- <memory>
- <new>
- <numeric>
-
<random>C++11
-
<ratio>C++11
-
<regex>C++11
- <stdexcept>
- <string>
-
<system_error>C++11
-
<tuple>C++11
-
<type_traits>C++11
-
<typeindex>C++11
- <typeinfo>
- <utility>
- <valarray>
<istream>
class templates
classes
manipulators
basic_istream
- basic_istream::~basic_istream
- basic_istream::basic_istream
member classes
member functions
non-member overloads
protected members
-
basic_istream::operator=C++11
-
basic_istream::swapC++11
-
- Reference
- <istream>
- basic_istream
- operator>>
public member function
<istream> <iostream>
std::operator>> (basic_istream)
single character (1) | template<class charT, class traits>basic_istream<charT,traits>& operator>> (basic_istream<charT,traits>& is, charT& c);template<class traits>basic_istream<char,traits>& operator>> (basic_istream<char,traits>& is, signed char& c);template<class traits>basic_istream<char,traits>& operator>> (basic_istream<char,traits>& is, unsigned char& c); |
---|---|
character sequence (2) | template<class charT, class traits>basic_istream<charT,traits>& operator>> (basic_istream<charT,traits>& is, charT* s);template<class traits>basic_istream<char,traits>& operator>> (basic_istream<char,traits>& is, signed char* s);template<class traits>basic_istream<char,traits>& operator>> (basic_istream<char,traits>& is, unsigned char* s); |
single character (1) | template<class charT, class traits>basic_istream<charT,traits>& operator>> (basic_istream<charT,traits>& is, charT& c);template<class traits>basic_istream<char,traits>& operator>> (basic_istream<char,traits>& is, signed char& c);template<class traits>basic_istream<char,traits>& operator>> (basic_istream<char,traits>& is, unsigned char& c); |
---|---|
character sequence (2) | template<class charT, class traits>basic_istream<charT,traits>& operator>> (basic_istream<charT,traits>& is, charT* s);template<class traits>basic_istream<char,traits>& operator>> (basic_istream<char,traits>& is, signed char* s);template<class traits>basic_istream<char,traits>& operator>> (basic_istream<char,traits>& is, unsigned char* s); |
rvalue extraction (3) | template<class charT, class traits, class T>basic_istream<charT,traits>& operator>> (basic_istream<charT,traits>&& is, T& val); |
Extract characters
>>
) applied to an input stream is known as extraction operator, and performs formatted input:- (1) single character
- Extracts the next character from is and stores it as the value of c.
- (2) character sequence
- Extracts characters from is and stores them in s as a c-string, stopping as soon as either a whitespace character is encountered or
(width()-1)
characters have been extracted (if width is not zero).
A null character (charT()
) is automatically appended to the written sequence.
The function then resets width to zero.
- (3) rvalue extraction
- Allows extracting from rvalue basic_istream objects, with the same effect as from lvalues: It effectively calls:
is>>val
.
Internally, the function accesses the input sequence of is by first constructing a sentry with noskipws set to
false
: this may flush its tied stream and/or discard leading whitespaces (see basic_istream::sentry). Then (if good), it extracts characters from is's associated stream buffer object (as if calling its member functions sbumpc or sgetc), and finally destroys the sentry object before returning.Notice that if this function extracts the last character of a stream when extracting a single character (1), it does not set its eofbit flag, but attempting to extract beyond it does.
Calling this function does not alter the value returned by gcount on is.
Parameters
- is
- Input stream object from which characters are extracted.
- c
- Object where the extracted character is stored.
- s
- Pointer to an array of characters where extracted characters are stored as a c-string.
is's member function width may be used to specify a limit on the number of characters to write.
- val
- Object where content is stored.
T shall be a type supported as right-hand side argument either by this function or by is's member function operator>>.
Return Value
The basic_istream object (is).The extracted value or sequence is not returned, but directly stored in the variable passed as argument.
Errors are signaled by modifying the internal state flags:
flag | error |
---|---|
eofbit | The function stopped extracting characters because the input sequence controlled by is has no more characters available (end-of-file reached). |
failbit | Either no characters were extracted, or these could not be interpreted as a valid value of the appropriate type. |
badbit | Error on stream (such as when this function catches an exception thrown by an internal operation). When set, the integrity of the stream may have been affected. |
If the operation sets an internal state flag that was registered with is's member exceptions, the function throws an exception of is's failure member type.
Example
|
|
This example demonstrates the use of some of the overloaded operator>> functions shown above using the standard basic_istream object cin.
Data races
Modifies c or the elements of the array pointed by s.Modifies is.
Concurrent access to the same stream object may cause data races, except for the standard stream objects cin and wcin when these are synchronized with stdio (in this case, no data races are initiated, although no guarantees are given on the order in which extracted characters are attributed to threads).
Exception safety
Basic guarantee: if an exception is thrown, all objects involved are in valid states.It throws an exception of member type failure if the resulting error state flag for is is not goodbit and member exceptions was set to throw for that state in is.
Any exception thrown by an internal operation is caught and handled by the function, setting is's badbit flag. If badbit was set on the last call to exceptions for is, the function rethrows the caught exception.
See also
- basic_istream::get
- Get characters (public member function)
- basic_istream::getline
- Get line (public member function)
- basic_ostream::operator<<
- Insert formatted output (public member function)
- basic_istream::sentry
- Prepare stream for input (public member class)
Home page | Privacy policy
© cplusplus.com, 2000-2025 - All rights reserved - v3.3.4s
Spotted an error? contact us
© cplusplus.com, 2000-2025 - All rights reserved - v3.3.4s
Spotted an error? contact us