This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: std::stringstream with std::cout error
- From: Jeffrey Walton <noloader at gmail dot com>
- To: mahmood n <nt_mahmood at yahoo dot com>
- Cc: gcc-help <gcc-help at gcc dot gnu dot org>
- Date: Fri, 3 Nov 2017 15:52:22 -0400
- Subject: Re: std::stringstream with std::cout error
- Authentication-results: sourceware.org; auth=none
- References: <237875.73079.bm@smtp226.mail.bf1.yahoo.com>
- Reply-to: noloader at gmail dot com
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