简体   繁体   中英

C++ Convert stringstream into ifstream?

I am working with two pieces of code,

The first class uses an AAssetManager (Android NDK object) to read an "asset" and save it's contents to a single string. It then turns the string into a stringstream and parses it.

The second class parses type ifstream, which must be associated with a file.

Is there some way I can convert a string or stringstream into an ifstream so I don't have to change the entirety of one of these classes?

You can turn the ifstream into an istream . An ifstream is simply a more specific form of an istream . A stringstream inherits from an istream , so you can just pass the stringstream directly. If this is not available to you, then you would store the string to a file, then reopen the file with an ifstream , and pass that ifstream to the second function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM