Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot convert std::stringstream<char> to const char*

Tags:

c++

string

I tried to run command with help of system() function, forwarding argument as in code below:

std::stringstream volume_control;
int volume_value = 5;
volume_control << "/usr/bin/amixer cset numid=1 " << volume_value << std::endl;
system(volume_control.str());

It doesn't work, because of unsuccessful conversion of std::stringstream to const char*.

I know that in std::string case I have method std::c_string() and If I'm right it returns exactly what I need const char* type, but in this case of stringstream that method does not exist. So what to do?


1 Answers

volume_control.str() returns a std::string type. You need to call std::string::c_str() or std::string::data() method on it.

A google search would have easily given you the answer.

system(volume_control.str().c_str());
like image 153
Shreevardhan Avatar answered May 16 '26 08:05

Shreevardhan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!