to_string is not a member of std

CodeLite installation/troubleshooting forum
edemirci
CodeLite Curious
Posts: 2
Joined: Fri Jun 08, 2018 12:34 am
Genuine User: Yes
IDE Question: c++
Contact:

to_string is not a member of std

Post by edemirci »

Hello,

I apologize if this post does not belong here. I am having an issue using to_string() function while using CodeLite and MinGW GCC 8.1 64bit compiler on Windows 10.

Any help in pointing me in the right direction would be greatly appreciated as I have reached out to the GNU GCC folks with no reply as of yet.

I have a main...

I am including:
#include <stdio.h>
#include <iostream>
#include <iomanip> //This allows the manipulation of output to align correctly using setw function
#include <Conversion.h> //custom class
#include <Area.h> //custom class
#include <string.h> //gain access to string class

I am using:
using namespace std;
using namespace ErolD_DS; //my namespace for custom classes

I have a piece of code that states:

for(unsigned int i = 1; i <= 6; i++)
{
double newArea = area.CalculateArea_EqTriangle(i);

cout << "Equilateral Triangle area: " + to_string(newArea) << endl;
}

There are two errors I receive depending on using scope resolution or not (which I shouldn't have to use)...
This code above will result in a compile error: 'to_string' was not declared in this scope

However, if I use scope resolution: std::to_string(newArea), which I shouldn't have to considering I'm using std namespace, it results in the error: 'to_string' is not a member of 'std'.

I have poked around on the internet and found that, a while back this was an issue prior to GNU GCC 4.8.1 version. Here is an example: https://stackoverflow.com/questions/191 ... le_rich_qa

The fix, for me, was to put this switch in place in the c++ compiler executable from within CodeLite: -std=c++11
I shouldn't have to do this because string, as I understand it, is part of the C++ standard and has been for a time... long before this version of the compiler. It's not as if it's like PI in the math class where I have to
#define _USE_MATH_DEFINES because PI is not technically part of the C++ standard...

I understand this may not be directly related to CodeLite, but I can't seem to get an answer as to why I have to put this option in the compiler within CodeLite.

Again, any help would be appreciated.

Thanks,

-Erol
User avatar
eranif
CodeLite Plugin
Posts: 6367
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: to_string is not a member of std

Post by eranif »

This is a C++ question and not a CodeLite related.
CodeLite is an IDE and not a compiler.
Make sure you have read the HOW TO POST thread
marcelinux
CodeLite Enthusiast
Posts: 17
Joined: Mon Nov 02, 2015 3:26 pm
Genuine User: Yes
IDE Question: C++
Location: Spain
Contact:

Re: to_string is not a member of std

Post by marcelinux »

edemirci wrote: #include <string.h> //gain access to string class
but, can you try:

Code: Select all

#include <string>
http://www.cplusplus.com/reference/stri ... =to_string
edemirci
CodeLite Curious
Posts: 2
Joined: Fri Jun 08, 2018 12:34 am
Genuine User: Yes
IDE Question: c++
Contact:

Re: to_string is not a member of std

Post by edemirci »

Hello,

#include <string> is the same thing as #include <string.h>, is it not? As I understand it, the .h is just the older form of inclusion... Am I missing something?

In either case, I'm sorry that I posted something that doesn't belong here... can anyone point me in the right direction so I may go forth and find my answer?
Post Reply