3

Been having the problem for a while. Searched thoroughly on stackoverflow and other sites to figure out the problem.

I have c++2011, using the latest version of cygwin for terminal, and GCC 4.8.3. I tried adding -std=c++0x and -std=gnu++0x to the command line, but neither of them fixed the problem. Here's the code I've been using the test if it will work. to anyone who can help!

#include <iostream>
#include <string>

using namespace std;

int main(){
    int a = 1;
    string b = to_string(a);
    cout<< b;
    return 0; 
}

Here's what I used to compile as well as the error:

$ g++ -std=gnu++0x stringTest.cpp -o stringTest stringTest.cpp: In function ‘int main()’: stringTest.cpp:8:24: error: ‘to_string’ was not declared in this scope string b = to_string(a);

                    ^

Anyone have any idea what's going on? I have an assignment due soon that I have to use this for and really need to get it working. Thanks in advance

  • 3
    Try with the `-std=c++11` option – Cory Kramer Nov 14 '14 at 18:34
  • @Cyber `-std=c++0x` and `-std=c++11` are supposed to have exactly the same effect. Do you have a concrete reason to think it might make a difference? –  Nov 14 '14 at 18:35
  • See [`std::to_string()`](http://en.cppreference.com/w/cpp/string/basic_string/to_string) – πάντα ῥεῖ Nov 14 '14 at 18:36
  • @DieterLücking `using namespace std;` *should* cover that, should it not? –  Nov 14 '14 at 18:37
  • @hvd No not concrete, more like a suspicion http://stackoverflow.com/questions/24589105/what-is-the-difference-between-std-c0x-and-std-c11 – Cory Kramer Nov 14 '14 at 18:39
  • Works fine - linux g++ 4.8.2 –  Nov 14 '14 at 18:40
  • For MinGW, [there is a comment in the GCC bugzilla that this cannot be implemented for 32-bit compilations due to limitations of the libraries used by GCC](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52015#c15). I'm not sure, but this might affect Cygwin as well. –  Nov 14 '14 at 18:41
  • Tried using -std=c++11 and that didn't work either. I've tried this on two separate computers as well. Bother running latest cygwin, and GCC 4.8.3. – Aubrey Sapp Nov 14 '14 at 18:42
  • @hvd, running x64 version of cygwin. How would I check to see if GCC is x86 or x64? – Aubrey Sapp Nov 14 '14 at 18:44
  • @AubreySapp In that case, if you installed GCC through Cygwin's setup, you should have an x64 version. To double-check, you could run `gcc -v` and see what it says for "Target". Unfortunately, if you've got an x64 version and it doesn't work, that means it's just not implemented for Cygwin. However, since you have an x64 OS, you could install the MinGW version of GCC and use that instead. –  Nov 14 '14 at 18:46
  • @hvd Target says "x86_64-pc-cygwin" – Aubrey Sapp Nov 14 '14 at 18:51
  • The "duplicate" talks about g++/MinGW, but this question is about g++/Cygwin (those are different products). g++/Cygwin does have the same bug though. – M.M Nov 14 '14 at 23:03
  • the gcc discussion thread is a pretty lame copout, it would be possible to implement this function without relying on other libraries. Perhaps better to say "nobody has the time/inclination to fix it" than "impossible". – M.M Nov 14 '14 at 23:09

0 Answers0