[ Web Proxy ]
URL:
Viewing: https://ru.cppreference.com/cpp/io/basic_istream/operator_gtgt2 [Back]  [Original]

operator>><div class="t-tr-text">(STD :: basic_istream)<div class="t-tr-dropdown"><div><div><div class="t-tr-dropdown-arrow-border"></div><div class="t-tr-dropdown-arrow"></div><div class="t-tr-dropdown-h">:</div><div class="t-tr-dropdown-orig">(std::basic_istream)</div><div class="t-tr-dropdown-notes"> [http://translate.google.com Google].<br/> . [http://en.cppreference.com/w/Cppreference:MachineTranslations ].</div></div></div></div></div> cppreference.com
cppreference.com

operator>><div class="t-tr-text">(STD :: basic_istream)<div class="t-tr-dropdown"><div><div><div class="t-tr-dropdown-arrow-border"></div><div class="t-tr-dropdown-arrow"></div><div class="t-tr-dropdown-h">:</div><div class="t-tr-dropdown-orig">(std::basic_istream)</div><div class="t-tr-dropdown-notes"> [http://translate.google.com Google].<br/> . [http://en.cppreference.com/w/Cppreference:MachineTranslations ].</div></div></div></div></div>

cppreference.com

<metanoindex/>

<tbody> </tbody>
template< class CharT, class Traits > basic_istream<CharT,Traits>& operator>>( basic_istream<CharT,Traits>& st, CharT& ch ); template< class Traits > basic_istream<char,Traits>& operator>>( basic_istream<char,Traits>& st, signed char& ch ); template< class Traits > basic_istream<char,Traits>& operator>>( basic_istream<char,Traits>& st, unsigned char& ch );
(1)
template< class CharT, class Traits> basic_istream<CharT,Traits>& operator>>( basic_istream<CharT,Traits>& st, CharT* s ); template< class Traits > basic_istream<char,Traits>& operator>>( basic_istream<char,Traits>& st, signed char* s ); template< class Traits > basic_istream<char,Traits>& operator>>( basic_istream<char,Traits>& st, unsigned char* s );
(2)
template< class CharT, class Traits, class T > basic_istream<CharT,Traits>& operator>>( basic_istream<CharT,Traits>&& st, T& value );
(3) ( C++11)
.
:
Performs character input operations.
Google.
. .

1)

ch.
:
Extracts a character and stores it to ch.
Google.
. .

2)

, , s. , :
:
Extracts successive characters and stores them at successive locations of a character array whose first element is pointed to by s. The extraction stops if one of the following conditions are met:
Google.
. .
  • ( ctype<CharT> ) . .
    :
    a whitespace character (as determined by the ctype<CharT> facet) is found. The whitespace character is not extracted.
    Google.
    . .
  • this->width() - 1
    :
    this->width() - 1 characters are extracted
    Google.
    . .
, CharT() .
:
In either case, an additional null character value CharT() is stored at the end of the output.
Google.
. .

3)

, RValue ( st >> value).
:
Calls the appropriate extraction operator, given an rvalue reference to an input stream object (equivalent to st >> value).
Google.
. .

(1-2) . , sentry , () ' , , ios_base :: skipws . , sentry true.
:
The (1-2) versions of the operator behave as formatted input functions. That is, they construct a sentry object at the beginning that flushes the tie()'d buffers if needed, checks for errors, and extracts and discards all leading whitespace characters unless the ios_base::skipws flag was cleared. The input is attempted only if the sentry object returns true.
Google.
. .

st
,
:
input stream to extract the data from
Google.
. .
ch
:
reference to a character to store the extracted character to
Google.
. .
s
:
pointer to a character string to store the extracted characters to
Google.
. .

st

#include <iostream>
#include <iomanip>
#include <sstream>

int main()
{
    std::string input = "n greetings";
    std::istringstream stream(input);
    char c;
    const int MAX = 6;
    char cstr[MAX];

    stream >> c >> std::setw(MAX) >> cstr;
    std::cout << "c = " << c << '\n'
              << "cstr = " << cstr << '\n';

    double f;
    std::istringstream("1.23") >> f; // rvalue stream extraction
    std::cout << "f = " << f << '\n';
}

:

c = n
cstr = greet
f = 1.23

.

std::basic_istream
(public -) []

Web Proxy Viewer  |  New URL  |  Original Page