What is the best way to pass information from java to c++?

后端 未结 8 1769
太阳男子
太阳男子 2021-02-07 04:59

I have a java application I need to pass some info to a C++ program. It has been suggested that I use some simple socket programming to do this. Is this the best way? If not

8条回答
  •  再見小時候
    2021-02-07 05:07

    A simple way to do this is using standard input and output:

    class MyTest {
        public static void main(String... args) {
            System.out.println("carpet");
        }
    } // Java
    
    #include 
    #include 
    int main() {
        string input;
        std::getline(std::cin, input);
        std::cout << "from java: " << input << std::endl; // output: carpet
    } // C++
    
    # start by piping java's output to c++'s input
    $ java MyTest | ./my_receive 
    

提交回复
热议问题