0

I have Eclipse installed on three Windows 7 systems, and one Linux machine. I got this in my code:

#include <string>
using std::to_string();

All except one system with Win7 has to_string() not resolved/declared. I have tried following suggestions from many pages including:

Turn off eclipse errors (that arent really errors)

None works. Even copying the entire eclipse folder does not help. I cant believe how they let this error persist. Any idea to fix this would be appreciated.

greg-449
  • 109,219
  • 232
  • 102
  • 145
CaTx
  • 1,421
  • 4
  • 21
  • 42
  • 2
    Eclipse CDT doesn't come with a compiler. You need to install one separately, e.g. Mingw32. And the syntax is `using std::to_string;` – rustyx Oct 14 '17 at 20:37
  • You can try `itoa`, almost same as `to_string` – Ali Sepehri-Amin Oct 14 '17 at 20:37
  • @Ali There is no such function as itoa() in C++. –  Oct 14 '17 at 21:03
  • To OP - you need a modern C++ compiler. And Eclipse is really a very poor C++ IDE. –  Oct 14 '17 at 21:04
  • @NeilButterworth, Eclipse promised multi-platform capacity. I am trying to move away from Windows, and thought it would be good for the transition. Seems like NetBeans will be a good friend. – CaTx Oct 14 '17 at 23:56
  • Since `std::to_string()` is a function from the C++11 standard library, it not being resolved is usually a sign of the project not being correctly configured for C++11 support. That's a common problem; see [this question](https://stackoverflow.com/questions/9131763/eclipse-cdt-c11-c0x-support). – HighCommander4 Oct 17 '17 at 01:00
  • Chief, I tried configuring Eclipse times and times again. It only frustrates me. I am not the only one plagued with it. There seems to be no permanent fix. – CaTx Oct 17 '17 at 19:23

1 Answers1

0

Thanks for the hate. The solution came from unexpected places.

  1. For my Linux system, I decided to install NetBeans 8.2 in frustration. The code with to_string() unresolved was copied over and tried to compiled. To my horror, to_string() was still not resolved, and the variable names came up unresolved.

    a. So I followed this fix first (for NetBeans 8.2, go with Run>Set Project Configuration>Customize..>C++ Compiler>General>Include Directories): Netbeans 7.2 shows "Unable to resolve identifier" , although build is successful

    b. Then, I needed to switch the C compiler to C11. For NetBeans 8.2, go with Run>Set Project Configuration>Customize..>C Compiler>Build>C Compiler>General>C Standard --> set to C11.

    c. Lastly, I needed to switch the C compiler to C++11. For NetBeans 8.2, go with Run>Set Project Configuration>Customize..>C++ Compiler>Build>C Compiler>General>C Standard --> set to C++11.

    Next, I did a 'Clean & Build Project.' The text editor still complained about not able to resolve 'string identifier'. However, the code built, and ran just fine. Afterwards, I went back to Eclipse out of curiosity. Lo and behold, to_string() was no longer an error. Something must have happened when I changed the settings with NetBeans, and solved the problem in Eclipse.

  2. On another Windows 7 previously freshly installed, I tried to compiled the same code with Eclipse. It did not build, as 'make' was missing. I used the Cygwin installer file to get that package, as well as the missing GCC packages. Everything built, and to_string() resolved. This seemed to suggest the problem was with the Cygwin installation on which Eclipse ran.

All things considered, Eclipse freaking sucks! @Neil Butterworth, I picked Eclipse trying to move away from Visual Studio and the Windows ecosystem. Eclipse promised multi-platform capability, which I thought would help with the transition. This to_string() problem's persistence, and multiple failed efforts to point to a C++11 standard make a very strong point. Eclipse can be a huge pain.

CaTx
  • 1,421
  • 4
  • 21
  • 42
  • OK, the joy for Eclipse on Linux was short-lived. to_string() error comes back again. – CaTx Oct 15 '17 at 00:16