1

Good day

I have searched high and low, yet no solution.

IDE: NetBeans IDE 8.2 MinGW: Using the "latest" MinGW compiler.

Original Issue:

I would like to convert an int to string.

Using this method, I attempted to convert to string, however

this proposed method std::to_string() results in the error when used(with the to_string as the error)

unable to resolve identifier to_string

Project dependancies:

#include <string>
#include <iostream>

Searching for a solution to this issue, 2 promonent solutions appeared here and here

Setting the C and C++ compiler versions should apparenlty solve this issue.

It did not, any suggestions?

Minimal Code:

#include <string>

struct User_VPN_Info{
    std::string name, expire;
    int DaysLeft;

    User_VPN_Info(){}

    User_VPN_Info(std::string _name, std::string _expire, int _DaysLeft){
        name = _name;
        expire = _expire;
        DaysLeft = _DaysLeft;
    }

    std::string getString(){
        return(name + " + " + expire + " + " + std::to_string(DaysLeft) + " ; ");                                                    
    }                                             //^_______^ problem here
};
Community
  • 1
  • 1
CybeX
  • 2,060
  • 3
  • 48
  • 115
  • 4
    `std::to_string` was added in C++11. Is there any chance NetBeans would be compiling with e.g. C++03? Is there a way to specify which version to use? – Cory Kramer Dec 15 '16 at 13:00
  • http://stackoverflow.com/questions/24591936/how-to-set-netbeans-to-use-c11 – Simon Kraemer Dec 15 '16 at 13:01
  • You should pass `-std=c++11` as a compiler option. – Ralph Tandetzky Dec 15 '16 at 13:03
  • @CoryKramer yes, I have the option of C++98, C++11, C++14. I have attempted using 11 and 14, reparsing the project after each change, still no luck – CybeX Dec 15 '16 at 13:07
  • @SimonKraemer see above – CybeX Dec 15 '16 at 13:07
  • @RalphTandetzky I am unsure where to add this, I check the project properties, Build>C++ Compiler. Here I have 5 options/settings. 1. Include Directories, 2. Include Headers, 3. Preprocessor Definitions, 4. Use Linker Libraries (check box), 5. C++ Standard, I selected C++11 now (options are c++98,11,14) – CybeX Dec 15 '16 at 13:09
  • Please show your actual (minimal) code – Useless Dec 15 '16 at 13:11
  • @KGCybex Sometimes, build configurations do not get updated properly. Try to select C++11 or C++14 and then *rebuild* the whole project. With *rebuild* I don't mean just build but removing all created files before recompiling. When you select *build*, then it might not work properly, because the generated binaries appear to be up to date and don't get compiled again. – Ralph Tandetzky Dec 15 '16 at 13:14
  • @Useless see post update – CybeX Dec 15 '16 at 13:17

2 Answers2

2

It is know issue with MinGW

gcc  -std=gnu++14 -Wall -Wextra  main.cpp
main.cpp: In function 'int main()':
main.cpp:24:26: error: 'to_string' was not declared in this scope
     cout<<to_string(a)<<endl;

gcc  --version

gcc.exe (GCC) 5.3.0

Instant of 'standard" MinGw you should use MinGW-w64 - for 32 and 64 bit Windows

/mingw-w64/i686-6.2.0-posix-dwarf-rt_v5-rev1/mingw32/bin
./g++   -std=c++14   main.cpp

compile without errors

If you want change toolchain in Netbeans you have to add new Tool Collection in project properties.

steff
  • 54
  • 5
  • thank you steff, after following your proposed solution, I have solved my problem, I unfortunately will not be marking this as the correct answer, although it did assist me and put me on the right path to solving the issue, I will post the solution will all the information, etc. but thank you! – CybeX Dec 15 '16 at 22:34
0

Before I answer the question, I would like to thank steff for guiding me in the right direction, thus allowing me to solve the problem, please give his answer an upvote if you deem it worthy.

My Installation Info

Product Version: NetBeans IDE 8.2 (Build 201609300101)
Java: 1.8.0_112; Java HotSpot(TM) 64-Bit Server VM 25.112-b15
Runtime: Java(TM) SE Runtime Environment 1.8.0_112-b15
System: Windows 10 version 10.0 running on amd64; Cp1252; en_ZA (nb)

Setting Up Netbeans, etc

Orignally, I had install mingw32, as specified by the netbeans documentation page for seting up netbeans with c++, this is to setup the compiler for c++ (since it appears not to do this automatically).

I follow all the steps, adding the path to the environment, and not changing any installation paths, to keep it as to the "tutorial" as possible.

After coding and importing code, I ran into the error mentioned above, and so steff suggested to use the MinGW64 compiler, where I had just used the mingw32 compiler.

Solution

Overview of steps taken (my solution)

  1. Install MinGW64
  2. Add toolchain (aka compiler)
  3. Change project toolchain ( aka compiler)

1.

MinGW64 setup found here from sourceforge

Install this, changing no settings ofcourse.

2.

Opening up netbeans > Tools > Options > C/C++ tab.

Here I have MinGW on the left, that is the pre installed compiler, which exists due to the installation instructions from the documentation page (the MinGW32 compiler/toochain which is giving the error)

Click Add (to add new compiler), browse to the location of the newly install MinGW64 compiler, mine is in:

C:\Program Files\mingw-w64\x86_64-6.2.0-win32-seh-rt_v5-rev1\mingw64\

Name the compiler something appropriate, I named mine "MinGW_64" and for the Tool Collection Family, select the "GNU MinGW", and click ok.

  • Now, adding the links to the compiler exe's.

In my case, I had to fill in 2 sections, namely the C Compiler field and the C++ Compiler field.

Please note I am unsure as to which specific exe the c++ fied should point to, I just selected the c++.exe, this compiler solved my problem, I am unsure of the gcc.exe

Please see image below as a reference.

enter image description here

After this is done, make the MinGW64 compiler your default compiler.

3.

Finally, if you have an open project in which this error occurs (which I assume is most probably the case), there is one last thing to do.

Right click on your project > Properties > Build.

Look for the option "Tool Collection", the corresponding compiler name should be "MinGW" (same name as that of the compiler I refered to earlier - the faulty one), this should be changed to the new MinGW_64 compiler you have just installed and added in the Tools > Options > C/C++ section.

DONE!

Close your project properties, the project should reparse automatically, if not, right click on project > Code Assistance > Reparse Project, wait for reparse and your problem should be solved.

I really hope this helps.

CybeX
  • 2,060
  • 3
  • 48
  • 115