I'm trying to build a utility class that I can re-use, that converts a std::string to a char*:
char* Foo::stringConvert(std::string str){
      std::string newstr = str;
      // Convert std::string to char*
      boost::scoped_array<char> writable(new char[newstr.size() + 1]);
      std::copy(newstr.begin(), newstr.end(), writable.get());
      writable[newstr.size()] = '\0'; 
      // Get the char* from the modified std::string
      return writable.get();
}
The code works when I tried to load the output from within the stringConvert function, however when used in other parts of my application, this function returns garbage.
For example:
Foo foo;
char* bar = foo.stringConvert(str);
The above code returns garbage. Is there any workaround for this kind of issue?
 
     
    