Function to convert from const char * to char**
I basically reject your code for admittance into the master branch.
This is not C++ code but primarily C and duplicates functionality that exists in the standard library.

Let's look at your interface first:

void str2arg(const char * str, std::vector&lt;char*&gt; &amp; arg, std::string &amp; memory) {


The parameter memory is only used internally to the function. It is not used externally and provides no utility. So get rid of it as a parameter. Make it an internal member of the function.

The parameter arg is used as an out parameter. You don't need to do this. Return the vector by value. This makes it very clear what you are doing. The optimizer will elide the copy and with move semantics in C++11 it will use move if it can not elide the copy. Summary: it is not an issue to return big values from functions the compiler will optimize away any issues (if for some reason it can't and you notice during benchmarking then you can have a look at using out parameters).

std::vector&lt;char*&gt; str2arg(const char * str);


Next issues is you are using pointers (and dropping the constness). Pointers are horrible and should only be used at the lowest level of your code for creating containers. Normally you can use normal objects to represent stuff. Here use std::string.

std::vector&lt;std::string&gt; str2arg(std::string const&amp; str);
                                             ^^^^^^  Allows you to pass a literal.
                                                     That can be converted to a string.


Why are pointers horrible:
They do not provide any semantic definition of ownership. Ownership is a very important concept in C++ as it defines who is responsible for deleting an object. Normally we use containers and smart pointers to define ownership of dynamic objects and we refer to other objects via references when we don't own them.

Const correctness is a big deal in C++ this is something you should take to heart very quickly. You drop the constness on your pointers thus leading to a possibility where people incorrectly use the pointer you return (by modifying the content of the string). This is a real problem if the string is actually const and will cause the program to crash.

Algorithm:

Much improvement can be done here.
Let us examine the utilities provided by the standard.

Note 1:

The stream operator&gt;&gt; when applied to a std::string will read one space separated word from the stream.

  std::string word;
  stream &gt;&gt; word;  // drops leading space and reads a single space delimited word.


Note 2:

The std::istream_iterator&lt;X&gt; are iterators that treat streams as forward containers. They read X from the stream using operator&gt;&gt; and you can then access the object of type X with the standard iterator methods. Use this in combination with std::string and you can read words from a stream.

 std::istream_iterator&lt;std::string&gt; loop(stream);
 std::istream_iterator&lt;std::string&gt; end;

 for(;loop != end;++loop)
 {    std::cout &lt;&lt; *loop &lt;&lt; ".\n";
 }


Since we now have an iterator to scan through a stream of words we can also apply the standard algorithms.

 // Assuming the loop above had not drained the stream.
 // The following alternative copies a stream into the vector one word at a time.
 std::vector&lt;std::string&gt;  data;
 std::copy(loop, end, std::back_inserter(data));


Also note that std::vector has a constructor that takes iterators so you can build it directly, rather than using an algorithm.

 std::vector&lt;std::string&gt;  data(loop, end);


So now that we have gone through all that we can re-code your function like this:

#include &lt;vector&gt;
#include &lt;string&gt;
#include &lt;sstream&gt;
#include &lt;iterator&gt;
std::vector&lt;std::string&gt; str2arg(std::string const&amp; str)
{
    std::stringstream  stream(str);
    std::vector&lt;std::string&gt;  result((std::istream_iterator&lt;std::string&gt;(stream)),
                                     std::istream_iterator&lt;std::string&gt;());
    return result;
}


Side note.

Since we mention command line args in other answers.
I like to convert the command line args into string before proceeding.

int main(int argc, char* argv[])
{
    std::vector&lt;std::string&gt;  args(argv+1, argv + argc);
}


main

int main()
{
    std::vector&lt;std::string&gt;  data = str2arg("   this is  a test   string   ");
    std::vector&lt;char*&gt;        ptr;
    // Doing it like this because I don't feel inclined to go look
    // up the appropriate iterator adapter to convert a string into a pointer.
    std::for_each(args.begin(), args.end(),
                  [&amp;ptr](std::string&amp; a){ptr.push_back(&amp;a[0]);});

    SomeCFunctionThatNeedsPointers(&amp;ptr[0]);
}


Main with Boost

#include &lt;boost/iterator/transform_iterator.hpp&gt;

int main()
{
    typedef boost::transform_iterator&lt;std::function&lt;char*(std::string&amp;)&gt;,
                                      std::vector&lt;std::string&gt;::iterator
                                     &gt;    ti;

    std::vector&lt;std::string&gt;  data = str2arg("   this is  a test   string   ");
    std::vector&lt;char*&gt;        ptr(ti(args.begin(), [](std::string&amp; x){return &amp;x[0];}), ti(args.end()));

    SomeCFunctionThatNeedsPointers(&amp;ptr[0]);
}