Thread: Java and C++ connectivity

  1. #1
    Lord CyKill
    Guest

    Question Java and C++ connectivity

    I am writing an application in C++ and have to read data from the files, Since file reading in Java is so much easy, Is there any way that I read the files through Java and then use the files' data in my c++ code, meaning all this happening at a single go!

  2. #2
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    There is no easy way to connect Java and C++ although its very much possible using JNI (native methods connectivity to C/C++). Just don't try it. You gain absolutly NOTHING from reading a file in a totally different language and transferring data. Reading files in C++ is just as easy, if not easier. This example reads in 3 integers from the file in text format.
    Code:
    #include <iostream>
    #include <fstream>   // the file stream library
    using namespace std;
    
    int main()
    {
        ifstream input("test.txt");   // open the file
        int a, b, c;
    
        input >> a >> b >> c;   // read in the variables
        cout << "The three variables in the file were: " << a << ", " << b << ", " << c << endl;
    
        return 0;
    }

Popular pages Recent additions subscribe to a feed