-1

I have problem with converting integer to string in C++ using CodeBlocks and GCC Compiler. I tried with this but it eject error:

#include <iostream>
#include <string>

int main()
{
    int clicks = 0;
    string code = to_string(clicks); //error: "to_string" was not declared in this scope
}

And also i tried:

#include <iostream>
#include <string>

int main()

{
    int clicks = 0;
    std::string code = std::to_string(clicks); // error: "to_string" is not memeber of "std"

}

Is there any solution? Pls help

Marko Stojkovic
  • 3,255
  • 4
  • 19
  • 20

2 Answers2

4

You need to have support for C++11. How I figured that out? I checked the ref here and saw the C++11 icon.

See this answer on how to do this.

It pretty much says to follow these steps:

  1. Go to Toolbar -> Settings -> Compiler
  2. In the "Selected compiler" drop-down menu, make sure "GNU GCC Compiler" is selected
  3. Below that, select the "compiler settings" tab and then the "compiler flags" tab underneath
  4. In the list below, make sure the box for "Have g++ follow the C++11 ISO C++ language standard [-std=c++11]" is checked
  5. Click OK to save
Community
  • 1
  • 1
gsamaras
  • 71,951
  • 46
  • 188
  • 305
2

You need to use stringstream like so:

stringstream ss;
ss << clicks;
std:string code = ss.str();

Include sstream.

Dwayne Towell
  • 8,154
  • 4
  • 36
  • 49