0

作为某些 NDK 工作的一部分,我正在尝试将以下 C++ 代码移植到 Android:

#include <fstream>

// ...

inline void trim(string & str, const string & delim = " \t\r\n")
{
    string::size_type pos = str.find_last_not_of(delim);
    if(pos == string::npos) str.erase(str.begin(), str.end());
    else
    {
        str.erase(pos+1);
        pos = str.find_first_not_of(delim);
        if(pos != string::npos) str.erase(0, pos);
    }
}

我在str.erase(pos+1);and得到以下消息str.erase(0, pos)

Invalid arguments '
Candidates are:
std::basic_string<char,std::char_traits<char>,std::allocator<char>> & erase(?, ?)
__gnu_cxx::__normal_iterator<char *,std::basic_string<char,std::char_traits<char>,std::allocator<char>>>    erase(__gnu_cxx::__normal_iterator<char *,std::basic_string<char,std::char_traits<char>,std::allocator<char>>>)
__gnu_cxx::__normal_iterator<char *,std::basic_string<char,std::char_traits<char>,std::allocator<char>>>     erase(__gnu_cxx::__normal_iterator<char *,std::basic_string<char,std::char_traits<char>,std::allocator<char>>>,     __gnu_cxx::__normal_iterator<char *,std::basic_string<char,std::char_traits<char>,std::allocator<char>>>)
'

我尝试了这里的建议,但没有帮助。相反,现在我收到一条新消息#include <fstream>

Unresolved inclusion: <fstream>

我需要做什么来解决这个问题?谢谢你。

更新:我正在尝试将这段代码添加到构建和运行良好的 Android 项目中的现有 C++ 代码中。当我应用上面链接的更改时,我不仅得到了unresolved inclusionfor fstream,而且还得到了一堆其他错误。例如,对于以下块,形成现有代码:

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

我也遇到Unresolved inclusion错误。所以事情变得更糟了。

4

1 回答 1

0

尝试将以下行添加到Application.mk您的项目中。

APP_STL := gnustl_static
于 2014-01-18T15:33:31.643 回答