Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

operator>> (<string>)


A template function that reads a string from an input stream.

template<class CharType, class Traits, class Allocator>
   basic_istream<CharType, Traits>& operator>>(
      basic_istream<CharType, Traits>& _Istr,
      basic_string<CharType, Traits, Allocator>& _Right


The input stream used to extract the sequence


The string that is being extracted from the input stream.

Reads the value of the specified string from _Istr and returns it into _Right.

The operator skips the leading white spaces unless the skipws flag is set. It reads all the following characters until the next character is a white space or the end of the file is reached.

The template function overloads operator>> to replace the sequence controlled by _Right with a sequence of elements extracted from the stream _Istr. Extraction stops:

  • At end of file.

  • After the function extracts _Istr.width elements, if that value is nonzero.

After the function extracts _Istr.max_size elements.

  • After the function extracts an element ch for which use_facet<ctype<CharType> >( getloc). is( ctype<CharType>::space, ch) is true, in which case the character is put back.

If the function extracts no elements, it calls setstate(ios_base::failbit). In any case, it calls istr.width(0) and returns *this.


// string_op_read_.cpp
// compile with: /EHsc
#include <string>
#include <iostream>

int main( )
   using namespace std;

   string c0;
   cout << "Input a string c0 ( try: Fibonacci numbers ): ";
   cin >> c0;
   cout << "The string entered is c0 = " << c0 << endl;

Fibonacci numbers

Input a string c0 ( try: Fibonacci numbers ): Fibonacci numbers
The string entered is c0 = Fibonacci


Header: <string>

Namespace: std

© 2016 Microsoft