How to add data to the database with C++?

Trying to write a program that would add, change and delete data in database in C++.
But it does not work to add the data entered from the keyboard.
As DBMS used is Postgresql
I tried using stringstream, it gives errors like this:

error: cannot convert ‘std::__cxx11::basic_stringstream::__string_type {aka std::__cxx11::basic_string}’ to ‘const char*’ for argument ‘2’ to ‘PGresult* PQexec(PGconn*, const char*)’

The code itself:

stringstream ss;

 ss << "INSERT INTO revenue VALUES(" << id << ", '" << name << "', '" << startBalance << "','" <<descript <<")";

 res = PQexec (conn, ss.str());

April 4th 20 at 00:44
1 answer
April 4th 20 at 00:46
str returns a string

PQexec takes
PQexec(PGconn*, const char*)

// ...

ostringstream os;
// ...

res = PQexec (conn, os.str().c_str());

// ...
Thank you very much!
Helped - Selena45 commented on April 4th 20 at 00:49

Find more questions by tags C++