0

I've been trying to use the stoi() function but it throws some weird error on DevC++5.11. Some of my friends are able to run it(On different IDE's or Text Editors), but i can't for some reason.

I've tried a lot of things (Compiler Options, Programs in Compiler Options, etc), but none of them have worked.

The code i'm trying to run is the next one:

out_file.open("calificaciones_disp.txt", ofstream::app); // Agrega líneas al archivo

    if (cuenta > 0) {
        int suma = 0;
        for (int i=0; i<cuenta; i++) {
            out_file << "Alumno: " << calificaciones[i][0] << " calificacion: " << calificaciones[i][1] << endl;
            suma += stoi(calificaciones[i][1]);
        }
        out_file << "Promedio: " << (double)suma/cuenta << endl;
    } else {
        out_file << "El archivo no tenia datos" << endl;
    }

    out_file.close(); 

This is what it shows in console:

terminate called after throwing an instance of 'std::invalid_argument' what(): stoi

So my question is, what can i do? or is there some IDE better than DevC++ that you'd recommend me? if so, any links?

Thank you in advance ;)

P.D.

My compiler Options

My Compiler Options->Code Generation settings

ArmsMG
  • 49
  • 1
  • 7
  • 4
    The exception means you gave it a bad value. What is `calificaciones[i][1]` when the exception fires? – NathanOliver Nov 13 '19 at 17:38
  • "or is there some IDE better than DevC++ that you'd recommend me?" - Why would you expect changing IDE/compiler to magically cause broken code to work?? What you use to write your code doesn't *matter* whether it's Emacs, Vim, Notepad, DevC++, Visual Studio or even MS Word *doesn't matter*. What matters is whether the text you eventually hand off to the compiler represents a *valid* program. See also [What is a debugger and how can it help me diagnose problems?](https://stackoverflow.com/q/25385173/5910058). – Jesper Juhl Nov 13 '19 at 17:40
  • @NathanOliver-ReinstateMonica the string is written to the file before the call to `stoi`, so it should be easy to determine. – Mark Ransom Nov 13 '19 at 18:12
  • When executing in an IDE there are variations in how exceptions are handled and typically there are settings that let the IDE intercept exceptions. A stand alone program will, of course, just terminate. – doug Nov 13 '19 at 18:22

0 Answers0