-1

UPDATE:

Not only does this affect the MinGW version of G++, it also affects the Cygwin version. I can't use mingw-64 as its Windows port (win-builds) does not install G++ properly (doesn't install required .dlls) and when I install them myself G++ doesn't even run. This makes the problem even more serious.

END UPDATE

So I want to compile some C++ code with G++:

#include <iostream>
#include <cstdlib>
#include <time.h>
#include <string>
using namespace std;
int main(int argc, char *argv[]) {
    int maxInt = stoi(argv[1]);
    srand(time(0));
    cout << rand() % maxInt << endl;
}

When I compile it though, I get this error:

test.cpp: In function 'int main(int, char**)':  
test.cpp:6:30: error: 'stoi' was not declared in this sopce
     int maxInt = stoi(argv[1]);
                              ^

I have tried compiling it with -std=c++11 and -std=c++0x, but it still gives this error. I am trying to compile it on a Windows 8.1 laptop with about 200 GB of free space. It has 4 GB of RAM, and has MinGW installed from SourceForge. I'm using GCC version 4.8.1, so if the version may be the case, please tell me where to get a higher version?

Community
  • 1
  • 1

1 Answers1

0

Since you are trying to parse a c-string, why not to use std::atoi? Remember to include cstdlib.

Ilio Catallo
  • 3,152
  • 2
  • 22
  • 40