<i id='3pdia'><tr id='3pdia'><dt id='3pdia'><q id='3pdia'><span id='3pdia'><b id='3pdia'><form id='3pdia'><ins id='3pdia'></ins><ul id='3pdia'></ul><sub id='3pdia'></sub></form><legend id='3pdia'></legend><bdo id='3pdia'><pre id='3pdia'><center id='3pdia'></center></pre></bdo></b><th id='3pdia'></th></span></q></dt></tr></i><div id='3pdia'><tfoot id='3pdia'></tfoot><dl id='3pdia'><fieldset id='3pdia'></fieldset></dl></div>
    1. <tfoot id='3pdia'></tfoot>

      <legend id='3pdia'><style id='3pdia'><dir id='3pdia'><q id='3pdia'></q></dir></style></legend>
      • <bdo id='3pdia'></bdo><ul id='3pdia'></ul>

      <small id='3pdia'></small><noframes id='3pdia'>

        如何将字符串向量传递给 execv

        时间:2023-09-15
          <tbody id='TR4Tw'></tbody>
        • <i id='TR4Tw'><tr id='TR4Tw'><dt id='TR4Tw'><q id='TR4Tw'><span id='TR4Tw'><b id='TR4Tw'><form id='TR4Tw'><ins id='TR4Tw'></ins><ul id='TR4Tw'></ul><sub id='TR4Tw'></sub></form><legend id='TR4Tw'></legend><bdo id='TR4Tw'><pre id='TR4Tw'><center id='TR4Tw'></center></pre></bdo></b><th id='TR4Tw'></th></span></q></dt></tr></i><div id='TR4Tw'><tfoot id='TR4Tw'></tfoot><dl id='TR4Tw'><fieldset id='TR4Tw'></fieldset></dl></div>

        • <small id='TR4Tw'></small><noframes id='TR4Tw'>

                <legend id='TR4Tw'><style id='TR4Tw'><dir id='TR4Tw'><q id='TR4Tw'></q></dir></style></legend>

                <tfoot id='TR4Tw'></tfoot>

                • <bdo id='TR4Tw'></bdo><ul id='TR4Tw'></ul>
                  本文介绍了如何将字符串向量传递给 execv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我发现构建我的程序参数列表的最简单方法是作为字符串向量.但是, execv 需要一个字符数组作为第二个参数.让它接受字符串向量的最简单方法是什么?

                  I have found that the easiest way to build my program argument list is as a vector of strings. However, execv expects an array of chars for the second argument. What's the easiest way to get it to accept of vector of strings?

                  推荐答案

                  execv() 只接受字符串指针数组.没有办法让它接受其他任何东西.它是一个标准接口,可从所有托管语言调用,而不仅仅是 C++.

                  execv() accepts only an array of string pointers. There is no way to get it to accept anything else. It is a standard interface, callable from every hosted language, not just C++.

                  我已经测试编译这个:

                  std::vector<string> vector;
                  const char *programname = "abc";
                  
                  const char **argv = new const char* [vector.size()+2];   // extra room for program name and sentinel
                  argv [0] = programname;         // by convention, argv[0] is program name
                  for (int j = 0;  j < vector.size()+1;  ++j)     // copy args
                          argv [j+1] = vector[j] .c_str();
                  
                  argv [vector.size()+1] = NULL;  // end of arguments sentinel is NULL
                  
                  execv (programname, (char **)argv);
                  

                  这篇关于如何将字符串向量传递给 execv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:原始 new[]/delete[] 与 std::vector 的优化 下一篇:C++:模板类的向量

                  相关文章

                  最新文章

                      <bdo id='OklfY'></bdo><ul id='OklfY'></ul>
                  1. <legend id='OklfY'><style id='OklfY'><dir id='OklfY'><q id='OklfY'></q></dir></style></legend>
                  2. <small id='OklfY'></small><noframes id='OklfY'>

                    <i id='OklfY'><tr id='OklfY'><dt id='OklfY'><q id='OklfY'><span id='OklfY'><b id='OklfY'><form id='OklfY'><ins id='OklfY'></ins><ul id='OklfY'></ul><sub id='OklfY'></sub></form><legend id='OklfY'></legend><bdo id='OklfY'><pre id='OklfY'><center id='OklfY'></center></pre></bdo></b><th id='OklfY'></th></span></q></dt></tr></i><div id='OklfY'><tfoot id='OklfY'></tfoot><dl id='OklfY'><fieldset id='OklfY'></fieldset></dl></div>
                    <tfoot id='OklfY'></tfoot>