1

I have a problem with converting int to string in Dev-C++.

I have the proper #include, but still I get:

[Error] 'to_string' is not a member of 'std'

const int MAX_KOSZT = 999999;    
string convert(int val) {
  if (val == MAX_KOSZT) 
  {
    return "--";
  } 
  else {
    if (val < 10) {
      return "0" + std::to_string(val);
    } 
    else {
      return std::to_string(val);
    }
  }
}

void getCout()
{
  cout << convert(sciana) << "," << convert(chodnik);
}
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
Bulit
  • 975
  • 6
  • 15
  • 26
  • 1
    Did you `#include `? C++11 standard is on? – πάντα ῥεῖ Mar 08 '16 at 17:40
  • I write that i got proper include. – Bulit Mar 08 '16 at 17:43
  • 1
    `Dev-C++` That is not a compiler. That is an IDE. What is the actual compiler used to compile your code? Probably some (old) version of gcc. – PaulMcKenzie Mar 08 '16 at 17:44
  • 2
    You should present a [MCVE] in your question though. Who knows what your understanding of _proper include_ is? – πάντα ῥεῖ Mar 08 '16 at 17:45
  • I've got completely different [compiler errors](http://ideone.com/7FHnoI) – πάντα ῥεῖ Mar 08 '16 at 17:47
  • PaulMcKenzie i use this -> TDM-GCC 4.9.2 64-bit Release – Bulit Mar 08 '16 at 17:48
  • @Bulit compile it with g++ compiler – Sudipta Kumar Sahoo Mar 08 '16 at 17:49
  • πάντα ῥε sory I assumed that word proper is clear – Bulit Mar 08 '16 at 17:49
  • 4
    @Bulit But why even have all of this code you've posted to test whether `std::to_string` works? Look at this: http://ideone.com/xndpeR See how simple that is. That's all you need to demonstrate to us to show us the issue. No missing headers, a complete, but minimal example, etc.. Now, does that example at the link compile for you? – PaulMcKenzie Mar 08 '16 at 17:53
  • Possible duplicate: [How to change mode from c++98 mode in Dev-C++ to a mode that supports C++0x (range based for)?](http://stackoverflow.com/questions/16951376/how-to-change-mode-from-c98-mode-in-dev-c-to-a-mode-that-supports-c0x-ran) – NathanOliver Mar 08 '16 at 17:54
  • @PaulMcKenzie i paste more code thx to what everyone can understand more is better than less NathanOliver Yes this can be possible duplicate but i didnt even know that there is mode change in Dev-C++ – Bulit Mar 08 '16 at 17:57
  • @Built -- More is not better if the issue is with a simple function. Any compiler error can be duplicated with a tiny amount of code, not entire functions with missing variables and headers. The code I linked to is the kind of example you should have started with on your own. – PaulMcKenzie Mar 08 '16 at 17:58
  • @PaulMcKenzie k i will remember that thx anyway – Bulit Mar 08 '16 at 18:47

1 Answers1

6

The compiler defaults to not having C++11 features available.

I suspect you need to change the language standard to ISOC++11 or GNUC++11 in the compiler settings.

If you are using a project, you will find this in the project options (right click on the project). If not, you will find this, I think, in the "tools" menu.

The option you need looks something like this http://www.cplusplus.com/doc/tutorial/introduction/devcpp/devcpp2.png

JeremyR
  • 401
  • 4
  • 8