I am interested in sharing data between Java and C++ so JNI. Currently all the C++ code expects a file so its all written in terms of std::ifstream. Rather than writing the files and reading them again, I would like to be able to just pass a char* over and have the application read from that instead somehow treating the char* as a ifstream. Is there anyway to create a ifstream that is based on a char* ?
Thanks
Yes, it’s called
std::istringstream. You can use it like this:If your code expects a
std::ifstreamspecifically, you could change it to expect a genericstd::istream, from which both inherit, as Adrian mentioned.