【问题标题】:how to write a c++ code for javascript "this.path.split('"/');"如何为 javascript "this.path.split('"/');" 编写 C++ 代码
【发布时间】:2014-07-03 06:58:35
【问题描述】:

我在制作 adobe 插件以获取打开文档的路径时遇到问题,当我刚刚尝试使用 javascript 工具在 Adob​​e 中插入工具箱时,我设法使用下面的脚本获取路径。

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

我想知道如何像这样在 c++ 中获取路径,或者只是如何在 c++ 中使用相同的代码类型。 请帮我解决这个问题。谢谢。

【问题讨论】:

  • 你可以试试 Boost FileSystem Library。除了具有 current_path 函数之外,它还提供了可移植的路径解析,否则很难正确解析。

标签: javascript c++ acrobat acrobat-sdk


【解决方案1】:

如果你使用的是纯 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;
}

来源:http://www.cplusplus.com/faq/sequences/strings/split/iostreams 和 getline() 部分已修改为使用向量。

【讨论】:

    【解决方案2】:

    我猜你想标记路径变量。如果有,请查看

    How do I tokenize a string in C++?

    【讨论】:

    • 感谢Sargi Eran的回复,只想用c++获取当前文档的路径。
    猜你喜欢
    • 2022-11-20
    • 1970-01-01
    • 1970-01-01
    • 2013-08-23
    • 2012-02-22
    • 1970-01-01
    • 1970-01-01
    • 2012-05-22
    • 2016-11-24
    相关资源
    最近更新 更多