This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
std::stringstream with std::cout error
- From: "mahmood n via gcc-help" <gcc-help at gcc dot gnu dot org>
- To: gcc-help <gcc-help at gcc dot gnu dot org>
- Date: Fri, 3 Nov 2017 22:37:26 +0330
- Subject: std::stringstream with std::cout error
- Authentication-results: sourceware.org; auth=none
- Reply-to: mahmood n <nt_mahmood at yahoo dot com>
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