Help: error C2039: 'to_string' : is not a member of 'std'

Hi,

I am trying to convert "int" to "string" on VS-2008 and I am getting the following errors:


error C2039: 'to_string' : is not a member of 'std'
error C3861: 'to_string': identifier not found

1
2
3
4
5
6
7
8
9
10
#include "stdafx.h"
#include <string>     // std::string, std::to_string


int main(int argc, char** argv)
{
	std::string perfect = std::to_string(5);
	return 0;
}


Any help would be appreciated.
Regards,
Dk
You need to have C++11 compatible compiler that can recognize the std::to_string function.
Fortunately, it's trivial to write your own:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <string>
#include <sstream>

template <typename T>
std::string to_string(T value)
{
	std::ostringstream os ;
	os << value ;
	return os.str() ;
}

int main()
{
	std::string perfect = to_string(5) ;
}
Sorry,

My knowledge of C++ is limited; so, would you please tell me what is C++11?

Also, can you suggest me how to convert to string on VS2008?

Regards,
DK
Last edited on
My knowledge of C++ is limited; so, would you please tell me what is C++11?


C++11 is the newer standard of C++ that came out in 2011. Older compilers (VS2008) don't really support it. If you upgrade your version of VS (or some other compiler like clang,gcc), you'll get a lot of new functionality like this.

Also, can you suggest me how to convert to string on VS2008?


cire just did. See his reply.
Topic archived. No new replies allowed.