You can adapt this example to work with the "buffer" mode of AAssetManager.
This will read the entire asset into memory, though. You could make an implementation that works more like std::fstream by reading chunks into a memory buffer, but that is significantly more complex.
Note: I only test-compiled the code below.
class asset_streambuf : public std::streambuf {
public:
asset_streambuf(AAsset * the_asset)
: the_asset_(the_asset) {
char * begin = (char *)AAsset_getBuffer(the_asset);
char * end = begin + AAsset_getLength64(the_asset);
setg(begin, begin, end);
}
~asset_streambuf() {
AAsset_close(the_asset_);
}
private:
AAsset * the_asset_;
};
Usage:
AAsset * asset = AAssetManager_open(mgr, "some_asset.bin", AASSET_MODE_BUFFER);
asset_streambuf sb(asset);
std::istream is(&sb);
EDIT: Found a shorter way based on this answer.