Type 'std::string' could not be resolved.
14,285
If the other answers didn't work, then try these steps:
- If you have
using namespace std;
, usestring
instead ofstd::string
. - If
#include <string>
doesn't work and you're using Linux, try#include <unistd.h>
. If you're using another OS, use#include <cstdlib>
.
Author by
LEX
Updated on June 05, 2022Comments
-
LEX almost 2 years
I'd started porting some Java code in native c++ in Android. I have an issue with using strings in c++:
Type 'std::string' could not be resolved
There is my sample code
#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 file:
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := native LOCAL_SRC_FILES := native.cpp include $(BUILD_SHARED_LIBRARY)
Application.mk file:
APP_STL := stlport_static
MinGW installed and added to path. I tried using android-ndk-r8e and android-ndk-r8-crystax-1 nothing helped. In Cygwin Terminal errors:
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'
I'm using Win 7 64bit. Can anyone say how it could be solved? Thanks.
EDIT.
In C/C++ General - Path and Symbols already set: C:\Android\android-ndk-r8e\platforms\android-14\arch-arm\usr\include
-
LEX over 10 yearsHi, I'm changed std::string to string, and added #include <string>. But Eclipse show errors "Type 'string' could not be resolved" although in cygwin compile fine.
-
Shervin Sorouri over 10 yearsThen eclipse has a problem but i suggest you try
#include <cstdlib>
for windows or#include <unistd.h>
for linux instead of#include <string>
-
LEX over 10 years#include <cstdlib> Eclipse accepted it, but warning didn't hide and compile in cygwing show error "'string' was not declared in this scope"
-
Shervin Sorouri over 10 yearsnow i am sure that your computer doesn't have the string header or your ide(Eclipse) is broken.
-
Shervin Sorouri over 10 yearsi recommend visual studio if your a windows user because its really easy to work with and its free. go check it at Microsoft's website
-
IInspectable over 10 years@shervin Visual Studio and Android's NDK aren't exactly best friends. It is possible to integrate the NDK into Visual Studio. However, vs-android is flaky, at best. And VisualGDB is a commercial product that requires a commercial Visual Studio Edition.
-
Parag Bafna about 9 yearsThis does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post.
-
Joe Plante about 9 yearsWow was this a long time ago. I'll update the answer. However, see kandroid.org/ndk/docs/CPLUSPLUS-SUPPORT.html
-
jww almost 9 years"But Eclipse show errors "Type 'string' could not be resolved" although in cygwin compile fine..." - Also see Android NDK build, Method could not be resolved. Eclipse and the plugin broke during a NDK update and it was never fixed. It was never fixed presumably because of Android Studio, which does not support JNI...