来自 C++ 的 JNI Java;打印输出?

Imm*_*009 0 c++ java java-native-interface stdout

我使用 JNI 在 C++ 程序中调用一些 Java 代码。我需要将一些文本从 Java 打印到 C++ 标准输出。

我该怎么做?

我尝试:System.out.println("sdf");在java中,什么也没有出现。

请帮助:D

Bra*_*don 5

public class Natives {
    public static native void printf(final String WhatToPrintHere);
}

public class Main {
    public static void main(String args[]) {
        Natives.printf("Testing printing from Java");
    }
}


extern "C" JNIEXPORT void Java_Natives_printf(JNIEnv* env, jobject obj, jstring WhatToPrintHere)
{
    const char* Str = env->GetStringUTFChars(WhatToPrintHere, 0);

    std::cout<< Str <<"\n";

    env->ReleaseStringUTFChars(WhatToPrintHere, Str);
}
Run Code Online (Sandbox Code Playgroud)