Time for action – read files with STL stream
Let's use the STL to read resources from the SD card instead of the application asset directory, as shown in the following steps:
- Obviously, enabling the STL is useless if we do not actively use it in our code. Let's take advantage of this opportunity to switch from asset files to external files (on a
sdcard
or internal memory).Open the existing file,
jni/Resource.hpp
, and do the following:- Include the
fstream
andstring
STL headers. - Use a
std::string
object for the file name and replace the Asset management members with anstd::ifstream
object (that is, an input file stream). - Change the
getPath()
method to return a C string from the newstring
member. - Remove the
descriptor()
method and theResourceDescriptor
class (descriptors work with the Asset API only) , as shown in the following:#ifndef _PACKT_RESOURCE_HPP_ #define _PACKT_RESOURCE_HPP_ #include "Types.hpp" #include <android_native_app_glue.h> #include <fstream...
- Include the