This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: std::stringstream with std::cout error


On Fri, Nov 3, 2017 at 3:07 PM, mahmood n via gcc-help
<gcc-help@gcc.gnu.org> wrote:
> ...
> Part of the code for that error is
>
> std::stringstream cmd;
> cmd << "a string”;
> int result = system(cmd.str().c_str());
> if(result){
>      std::cout << "Failed to execute: " << cmd << std::endl;
>      exit(1);
> }
>
> I changed that cout line to  cmd.str() and the error disappeared. However, I am not if I have to use cmd.str().c_str()?

You may want to change it to:

    std::cout << "Failed to execute: " << cmd.str() << std::endl;

It will print try to print embedded NULL's too in the case you have an
one in your command.

Jeff


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]