C++ - Read from either file or in-memory buffer with the same function -


is there single standard c/c++ function takes either file handle/pointer or pointer in-memory buffer , reads data file/buffer?

i have function pulls data file, performs operations on said data, , sends out on socket. have function takes data in form of char buffer, performs same operations on data, , sends on socket. problem isn't hard. thought convenient if there function

read(void *dest, void *src, int src_type, size_t amount) 

in c++ can use std::istream abstraction on top of file std::ifstream implementation, or in-memory buffer std::istringstream implementation.

the beauty of approach function not need know implementation type, because receiving argument reference sufficient:

void readdata(std::istream& in_data) {     ... } 

the caller construct appropriate implementation, , pass readdata.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -