C + + Extract text data from a standard stream

Source: Internet
Author: User

IStream & IStream:: Get (char *, int, char = ' \ n ');

IStream & IStream:: Getline (char *, int, char = ' \ n ');

Function: Extracts the specified number of characters from the text and adds a null character at the end of the string array

Where the first argument points to a character array that accepts character data

The second parameter specifies the maximum number of characters that a character array can hold

The third parameter is used to specify a terminator, which is the default line break character

The extraction terminates when the operation encounters a terminator or extracts to a specified number character

Difference: Get () does not extract the terminating character from the stream, and the terminating character is still in the input stream

Getline () extracts the terminating character from the stream, but the terminating character is discarded

1#include <iostream>2 using namespacestd;3 intMain ()4{CharBUF [ the ] ;5Cin.Get(BUF, the,'y') ;//specifying a terminating character6cout << buf << Endl;//default terminator ' \ n '7Cin.Get(BUF, the ) ; 8cout << buf <<Endl;9Cin.getline (BUF, the,'N' ) ;Tencout << buf <<Endl; OneCin.Get(BUF, the ) ;  Acout << buf <<Endl; -    return 0; -}
1#include <iostream>2#include <fstream>3 using namespacestd;4 intMain ()5{Ifstream inf ("d:\\testnew" ) ; 6    CharBUF [ the ] ;7Inf.getline (BUF, the ) ; 8cout << buf <<"____"<< Inf.gcount () <<Endl;9On.Get(BUF, the ) ; Tencout << buf <<"____"<< Inf.gcount () <<Endl; One inf.close (); A}

C + + Extract text data from a standard stream

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.