istream& istream::get(char& ref_c)
It is a function belonging to the streams of C ++ which is used to obtain the current character within the stream and advance to the next position.
Consider the following text file (hello.txt) :
Hola Mundo
When you open hola.txt
in a istream
, the position starts at the zero index of the file, so when% istream::get(c)
in the variable containing the file, you will get the letter H
stored in the variable c
and the file will now point to the next letter ( o
) .
See the following code;
#include <iostream>
#include <fstream>
int main()
{
std::ifstream is("hola.txt");
while (is.good())
{
char c = 0;
is.get(c);
std::cout << "El caracter actual es: " << c << '\n';
}
is.close();
return 0;
}
You get by result:
El caracter actual es: H
El caracter actual es: o
El caracter actual es: l
El caracter actual es: a
El caracter actual es:
El caracter actual es: M
El caracter actual es: u
El caracter actual es: n
El caracter actual es: d
El caracter actual es: o
El caracter actual es:
Reference: C ++ Reference .