Search code examples
c++android-ndkjava-native-interface

std::getline get error in JNI


I am using jni and want to read file from path, i used:

while (std::getline(file, str)) {
...

}

but it get an error : Function 'getline' could not be resolved, i have added:

#include <vector>
#include <string.h>
#include <jni.h>
#include <fstream>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <iostream>

and they are Ok. How do i resolved this problem? Please help me.


Solution

  • use:

    #include <string>
    

    instead of:

    #include <string.h>
    

    The latter one is the C variant and will not have the std namespace. Also see:

    Difference between <string> and <string.h>?