我开始将一些Java代码移植到Android的本地C++中。我在使用C++字符串时遇到了一个问题:
Type 'std::string' could not be resolved
这是我的样例代码。
#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;
}
Android.mk文件:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := native
LOCAL_SRC_FILES := native.cpp
include $(BUILD_SHARED_LIBRARY)
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'
我正在使用Win 7 64位操作系统。有人能说一下如何解决吗? 谢谢。
编辑。
在C/C++常规-路径和符号中已经设置为:C:\Android\android-ndk-r8e\platforms\android-14\arch-arm\usr\include
#include <string>
,<string.h>
是一个C语言库头文件。 - jrokusing namespace std;
的方法根本就不存在。 - The Forest And The Trees