1

the following code generates error

std::string xyz="whatever";
int x=1;
xyz+=std::to_string(x);
//this is supposed to turn xyz into whatever1 from whatever

Why am I using this approach? Because prepared statements are not working with the version of mysql on my ubuntu(there's a bug with this mysql version), and I have tried and followed everything to upgrade the mysql, but Alas! So, where I was supposed to do this

sql::preparedStatement* pstm=con->prepare_Statement("select x from y where a=?");
pstm->setString(1,"xyz");

I am getting a segmentation fault, core dump error in above. It's a common bug with the version of mySQL that I have in UBUNTU.After trying all I could to upgrade mysql, I have decided to not use prepared statements at all. Instead i decided to make queries like

std::string query="select x from y where a=";
int x=5;
query+=std::to_string(x);

And KUDOS! The g++ version doesn't support C++11 features, and thus to_string is not a part of std. I've tried the following commands

sudo apt-get update
sudo apt-get upgrade g++

No luck, yet. Any help will be highly appreciated

PS, for the time being, I am using this approach to concatenate integers with string

sstream ss; ss

But, I don't want to just keep switching ways just because I can not update a bloody feature of Ubuntu, nobody wants that. Right?

1 Answers1

0

g++ does support c++11, but it is experimental, hence you have to enable it with the option -std=gnu++11. You don't need to upgrade g++, you can't, because you are already running the latest version.

So you will compile using a command like

g++ -std=gnu++11 ./source_file.cpp

You may also try the clang compiler, as it has better c++11 support than g++. To install it, run

sudo apt-get install clang-3.5

Do read Status of Experimental C++11 Support in GCC 4.8 and C++ Support in Clang.

Registered User
  • 9,631
  • 14
  • 53
  • 85