itsols itsols - 16 days ago 4x
C++ Question

Quoting strings in C++

In Pascal Lazarus/Delphi, we have a function QuotedStr() that wraps any string within single quotes.

Here's an example of my current C++ code:

//I need to quote tblCustomers
pqxx::result r = txn.exec( "Select * from \"tblCustomers\" ");

Another one:

//I need to quote cCustomerName
std::cout << "Name: " << r[a]["\"cCustomerName\""];

Similar to the above, I have to frequently double-quote strings. Typing this in is kind of slowing me down. Is there a standard function I can use for this?

BTW, I develop using Ubuntu/Windows with Code::Blocks. The technique used must be compatible across both platforms. If there's no function, this means that I must write one.

String str = "tblCustomers";
str = "'" + str + "'";

See more options here