Book Image

Android NDK: Beginner's Guide

By : Sylvain Ratabouil
Book Image

Android NDK: Beginner's Guide

By: Sylvain Ratabouil

Overview of this book

Table of Contents (18 chapters)
Android NDK Beginner's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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:

  1. 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 and string STL headers.

    • Use a std::string object for the file name and replace the Asset management members with an std::ifstream object (that is, an input file stream).

    • Change the getPath() method to return a C string from the new string member.

    • Remove the descriptor() method and the ResourceDescriptor 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 <string...