1

I'm trying compile this code in cmd:

#include <iostream>
#include <string>
using namespace std;

int main(){
    int n = 24;
    string s = to_string(n);
    cout<<s;
}

I found in another qestions, that I should use this command:

g++ -std=c++11 main.cpp

but I get error:

main.cpp: In function 'int main()':
main.cpp:7:24: error: 'to_string' was not declared in this scope
  string s = to_string(n);
                        ^

I have latest g++ compiler for Windows v. 5.3.0. I used this installer for MinGW. I tried solve in to_string is not a member of std, says g++, but this patch doesn't work.

How can I compile this code in command line in Windows?

Community
  • 1
  • 1
Lukasz Re
  • 79
  • 1
  • 11
  • Is this the real code, that you use for the test? – Kiril Kirov Jan 11 '17 at 12:30
  • yes, it's exactly the same code. – Lukasz Re Jan 11 '17 at 12:33
  • this issue looks similar : http://stackoverflow.com/questions/12975341/to-string-is-not-a-member-of-std-says-g – apapa Jan 11 '17 at 12:40
  • Maybe it's the compiler version. I can compile this perfectly fine with my g++ 5.4 (Linux), it can be compiled with g++ 5.2 (via cppreference.com), but cannot be compiled with ideone.com with g++ 5.1 (only with C++14 option can, it probably uses a newer version). Even gcc 4.7 can compile this, it really seems like a compiler issue. – Kiril Kirov Jan 11 '17 at 12:41
  • 1
    Possible duplicate of [to\_string is not a member of std, says g++](http://stackoverflow.com/questions/12975341/to-string-is-not-a-member-of-std-says-g) – Mike Kinghan Jan 11 '17 at 14:05
  • BTW, consider using this mingw distro https://nuwen.net/mingw.html – Grisha Jan 11 '17 at 16:48
  • @Grisha this distro is working thank you very much. Btw its very weird that this issue disapears. – Lukasz Re Jan 11 '17 at 17:04

0 Answers0