Problem of creating NDK with C ++ in Android

I am currently working with Android NDK and JNI. I am trying to build C ++ code with NDK.

But I got the following errors:

E:/Android/Tranining_workspace/BackUpMigrant/jni/ReadBackupArc5/ReadBackupArc5.cpp:10:19: error: fstream: No such file or directory E:/Android/Tranining_workspace/BackUpMigrant/jni/ReadBackupArc5/ReadBackupArc5.cpp:20: error: 'ifstream' does not name a type E:/Android/Tranining_workspace/BackUpMigrant/jni/ReadBackupArc5/ReadBackupArc5.cpp:21: error: 'ofstream' does not name a type E:/Android/Tranining_workspace/BackUpMigrant/jni/ReadBackupArc5/ReadBackupArc5.cpp:22: error: 'ofstream' does not name a type E:/Android/Tranining_workspace/BackUpMigrant/jni/ReadBackupArc5/ReadBackupArc5.cpp:34: error: 'string' was not declared in this scope 

Can anyone help me out?

+7
source share
2 answers

I ran into the same problem. It seems that STL is not automatically included in NDK projects by default. It also means iostream , fstream , string , etc. Cannot be used immediately. To enable them, you need to modify your Application.mk file. If you don’t have it (it is in the <project>/jni ), just create a new one, empty. Add a line:

 APP_STL := stlport_static 

Also, be sure to include using namespace std; or equivalent along with the usual #include <iostream> , etc.

+11
source

Do you remember:

 #include <iostream> using namespace std; 

at the top of the file?

("Using the std namespace" is not always a good idea, but this is a separate issue.)

0
source

All Articles