basic_istream::readsome() in C++ with Examples
The basic_istream::readsome() used to read the data from the buffer and extracts up to n immediately available characters from the input string. This function returns the number of extracted characters. Below is the syntax for the same:
Header File:
#include<iostream>
Syntax:
streamsize readsome(char_type* a,
streamsize n);
Parameters:
- n: It represent maximum number of character to be read.
- a: It is the pointer to array where the extracted characters are stored.
Return Value: The std::basic_istream::readsome() returns the number of extracted characters.
Below are the programs to understand the implementation of std::basic_istream::readsome() in a better way:
Program 1:
#include <bits/stdc++.h>
using namespace std;
int main()
{
char gfg[50] = {};
istringstream gfg1( "GeeksforGeeks" );
gfg1.readsome(gfg, 3);
gfg1.readsome(gfg, 6);
cout << gfg << endl;
}
|
Program 2:
#include <bits/stdc++.h>
using namespace std;
int main()
{
char gfg[50] = {};
istringstream gfg1( "Computer" );
gfg1.readsome(gfg, 2);
gfg1.readsome(gfg, 3);
cout << gfg << endl;
}
|
Reference: http://www.cplusplus.com/reference/istream/basic_istream/readsome/
Last Updated :
28 May, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...