Access a block of memory (/ C/C++ array) as if it were a file stream
c, c++, cfstream, fstream
Solution
In C you may use `sprintf` and `sscanf`, in `C++` there is the std::stringstream class that is constructed using a string. So you may make the function take an `std::istream` as argument and pass either `std::ifstream` of `std::istringstream` depending on the case.
Problem
Is there a way to do this in C (or C++)? Background info: I'm going to be reading either a memory block or a large file line by line and processing those lines one at a time and I'm lazy to write the same thing twice, once for memory blocks and once for file streams. If the file stream version needs to be used, then the file won't fit into memory. Understandably, I could save the memory block to a file, and then access the same data with a file stream, but that seams like a waste of computer time. I know about /dev/shm on linux systems. Is there something more portable that gives me the same kind of abstraction at the layer of the language (C or C++)?