String Logic Error

  • cyberdragon
    28th Mar 2013 Member 0 Permalink

    I just converted a C++ program from using extended characters to basic strings. But now it crashes on startup with the following error:

     

    terminate called after throwing an instance of 'std::logic_error'

     what(): basic_string::_S_construct null not valid

     

    The input function I use is this

     

    string getString()
    {
    fflush(stdin);
    fflush(stdout);
    string io;
    cin >> io;
    cout << io << endl; //input test/confirm
    return io;
    }

     

    Is it this or something else?

    (note: I already tested the buffer flushes and they aren't causing the problem)

  • MiningMarsh
    30th Mar 2013 Member 0 Permalink

    Pastebin the entire program. This shouldn't be causing a crash, so I suspect its somewhere else in your program.

     

    Also, why teh convert to strings? Any particular reason?

  • cyberdragon
    30th Mar 2013 Member 0 Permalink

    Quit working with constant characters, kept giving segmentation faults. I don't know why, it was working before. The program is over 1400 lines...single page, but I'll get rid of the easter eggs and junk first, then I'll pastebin it.

     

    EDIT:I commented out the entire main function and it still crashed. It has to be in the other fuctions or variable declarations.

     

    void fatal(string message)
    {
    cout << "fatal " << message << endl;
    PlaySound("F:\\am-i-totally-screwed-or.wav", NULL, SND_SYNC);
    exit(-1);
    }

     

    float totalResistance = 0;
    float totalCapacitance;
    const double PI = 4.0*atan(1.0);
    double e = 2.71828182845904523536028747135266249775724709369995; /// if needed
    (((((string typeOfCircuit = (0);))))) EDIT: Naughty, Naughty variables.
    (((((string connection = (0);)))))))
    float C = 0;
    int count = 0;
    int R[0];
    float Ca[0];
    float L[0];
    float ca[0];
    double incvrt = 0.0393700787;

  • mniip
    31st Mar 2013 Developer 0 Permalink
    @cyberdragon (View Post)
    there's no need to do those precise constants
    only 16 digits can fit in a double.
    even if you use extended, still, 31 is the max