Search code examples
javascriptc++acrobatacrobat-sdk

how to write a c++ code for javascript "this.path.split('"/');"


I have problem in making a adobe plugin to get the path of the open document, when i just tried javascript tool to insert a tool box in Adobe, In that i managed to get the path using the script below.

  var path = this.path.split('"/');

I want know how to get the path in c++ Like this or just how to use the same code type in c++. Please help me with this Thank you.


Solution

  • If you are using plain c++, you can use the following code:

    #include <iostream>
    #include <string>
    #include <sstream>
    #include <algorithm>
    #include <iterator>
    #include <vector>
    
    int main() {
      using namespace std;
      vector<string> v;
      string s = "/path/to/foo/bar";
      istringstream iss(s);
      while (!iss.eof())
      {
        string x;
        getline(iss, x, '/');
        v.push_back(x);
      }
    
      for (vector<string>::iterator it = v.begin() ; it != v.end(); ++it)
        cout << *it << endl;
    }
    

    Source: http://www.cplusplus.com/faq/sequences/strings/split/, section iostreams and getline() modified to use a vector.