简体   繁体   English

如何为javascript“ this.path.split('” /');”编写C ++代码

[英]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. 当我刚尝试使用javascript工具在Adobe中插入工具箱时,我在制作adobe插件来获取打开文档的路径时遇到问题,因为我设法使用下面的脚本来获取路径。

  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++. 我想知道如何像这样在c ++中获取路径,或者只是如何在c ++中使用相同的代码类型。 Please help me with this Thank you. 请帮助我,谢谢。

I guess you want to tokenize path variable. 我猜你想标记路径变量。 If so have a look on 如果是这样看

How do I tokenize a string in C++? 如何在C ++中标记字符串?

If you are using plain c++, you can use the following code: 如果您使用的是纯c ++,则可以使用以下代码:

#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. 来源: http : //www.cplusplus.com/faq/sequences/strings/split/,iostreams和getline()部分已修改为使用向量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM