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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Mahmood,

This is not a problem specific to gcc.  It's a general C++ question. You
should post such questions
to places like StackOverflow or read a basic C++ book.

There is no operator `ostream& operator << (ostream&, const
stringstream&)`, thus the error.

There are operators that support both output of C++ strings and C-type
strings (NULL terminated character
arrays) to an ostream, so either of the options that you suggested below
will work.  It's up to you.

On Fri, Nov 3, 2017 at 3:07 PM, mahmood n via gcc-help <gcc-help@xxxxxxxxxxx
> wrote:

> Hi,
> A code is fine with gcc-4.8. However, with gcc-5.4, I get
>
> error: no match for ‘operator<<’ (operand types are
> ‘std::basic_ostream<char>’ and ‘std::stringstream {aka std::__cxx11::basic_
> stringstream<char>}’)
>     std::cout << "Failed to execute: " << cmd << std::endl;
>                                        ^
> note: candidate: operator<<(int, int) <built-in>
> note:   no known conversion for argument 2 from ‘std::stringstream {aka
> std::__cxx11::basic_stringstream<char>}’ to ‘int’
>
>
> 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()?


> Regards,
> Mahmood
>

-- 
Andrew Bell
andrew.bell.ia@xxxxxxxxx




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux