无法解析类型“std::string”。 我开始在Android中移植一些本地C++ java代码。我在c++中使用字符串时遇到问题: Type 'std::string' could not be resolved

无法解析类型“std::string”。 我开始在Android中移植一些本地C++ java代码。我在c++中使用字符串时遇到问题: Type 'std::string' could not be resolved,android,c++,android-ndk,native,Android,C++,Android Ndk,Native,这是我的示例代码 #include <jni.h> #include <lexu_me_test_native.h> #include <string.h> using namespace std; JNIEXPORT jstring JNICALL Java_lexu_me_test_native_prepairToShowNative (JNIEnv * env, jclass javaThis, jstring str) { jboolea

这是我的示例代码

#include <jni.h>
#include <lexu_me_test_native.h>
#include <string.h>
using namespace std;

JNIEXPORT jstring JNICALL Java_lexu_me_test_native_prepairToShowNative
  (JNIEnv * env, jclass javaThis, jstring str)
{
    jboolean blnIsCopy;
    jstring jstrOutput;
    char* strCOut;
    std::string ss;

    const char* strCIn = (env)->GetStringUTFChars(str , &blnIsCopy);
    // convert jstring to a char array
    // Do stuff with the char array and and store the result
    // in another char array strCOut
    (env)->ReleaseStringUTFChars(str , strCIn); // release jstring

    jstrOutput = (env)->NewStringUTF(strCOut); // convert char array to jstring
    return jstrOutput;
}
Application.mk文件:

APP_STL := stlport_static
MinGW已安装并添加到路径。我试过使用android-ndk-r8e和android-ndk-r8-crystax-1,但没有任何帮助。在Cygwin终端错误中:

Compile++ thumb  : native <= native.cpp
jni/native.cpp: In function '_jstring* Java_lexu_me_test_native_prepairToShowNative(JNIEnv*, jclass, jstring)':
jni/native.cpp:11:2: error: 'string' was not declared in this scope
jni/native.cpp:11:9: error: expected ';' before 'ss'
我用的是Win7 64位。有人能说怎么解决吗? 谢谢

编辑


在C/C++中,常规-路径和符号已设置:C:\Android\Android-ndk-r8e\platforms\Android-14\arch arm\usr\include

如果其他答案无效,请尝试以下步骤:

如果您使用了命名空间std;,使用string而不是std::string。 如果include不起作用,并且您正在使用Linux,请尝试include。如果您正在使用其他操作系统,请使用include。 检查您的Android.mk和Application.mk文件。确保选择STL库并在Application.mk文件中包含int:

APP_STL := stlport_static
gnustl_static可以替换为您想要的STL版本,STLPort仍然是一个选项


请参见

include,是一个C库头。使用命名空间std;请尝试字符串而不是std::string@Jite别这么说@jrok include导致未解析的包含:也包括在内;一点也不。嗨,我将std::string更改为string,并添加了include。但是Eclipse显示错误类型“string”无法解决,尽管在cygwin中编译很好。然后Eclipse出现问题,但我建议您尝试包含windows或包含linux,而不是包含Eclipse接受它,但警告未在cygwing中隐藏和编译显示错误“string”未在此范围内声明现在我确信您的计算机没有字符串头或您的ideEclipse已损坏。如果您是windows用户,我建议您使用visual studio,因为它非常容易操作且免费。在这里检查一下,这并不能提供问题的答案。若要评论或要求作者澄清,请在其帖子下方留下评论。哇,这是很久以前的事了。我会更新答案。但是,请参见
Application.mk: APP_STL := gnustl_static