The function get of an ifstream reads the next character and stores it in the argument you pass to the function. Example program:
#include <iostream>
#include <fstream>
int main () {
std::ifstream is("input.txt"); // open file
char c;
while (is.get(c)) // loop getting single characters
std::cout << c;
is.close(); // close file
return 0;
}
This works great but I am puzzled by how c can be changed by the function get as it is not passed by its pointer. I was told, some time ago, that modifying a variable within a function cannot change its value outside the function. And that's the whole purpose of pointers, right -- manipulating an object created outside the function. So how can c be changed here?
I guess there is something obvious that I don't understand here?