#"stof argument out of range"

43 messages · Page 1 of 1 (latest)

woeful violetBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

#

@minor scarab

Screenshots!

Your message appears to contain screenshots but no code. Please send code and error messages in text instead of screenshots if applicable!

minor scarab
#

int main()
{
vector <Flight> flightsvector;
string line;
string datachannel;
vector<string> seatsvector;
int numofiterations = 60;
int counter = 0;
int i = 0;
bool usercheck = false;

ifstream file("flightlist.txt");

if (!file.is_open()) {
    cout << "Error abriendo archivo." << endl;
    return 0;
}

while (true) {

    flightsvector.push_back(Flight());

    //DIVIDER

    if (!getline(file, datachannel)) break;
    flightsvector[counter].setDate(datachannel);

    if (!getline(file, datachannel)) break;
    flightsvector[counter].setHour(datachannel);

    if (!getline(file, datachannel)) break;
    flightsvector[counter].setPrice(stof(datachannel));

    if (!getline(file, datachannel)) break;
    flightsvector[counter].setAirplaneModel(datachannel);

    if (!getline(file, datachannel)) break;
    flightsvector[counter].setFromTo(datachannel);

    if (!getline(file, datachannel)) break;
    flightsvector[counter].setDistance(stof(datachannel));

    if (!getline(file, datachannel)) break;
    flightsvector[counter].setCrew(datachannel);

    if (!getline(file, datachannel)) break;
    flightsvector[counter].setFuel(stof(datachannel));

    while (i <= numofiterations) {
        if (!getline(file, datachannel)) break;
        seatsvector.push_back(datachannel);
        i = i + 1;
    }
    flightsvector[counter].setSeats(seatsvector);
    counter = counter + 1;
}

file.close();

}

woeful violetBOT
#
How to Format Code on Discord
Markup

```cpp
int main() {}
```

Result
int main() {}
vapid crown
#

i recommend checking out value is failing via the debugger

minor scarab
#

Hello

#

Value is failing?

#

i'm very postifive it's the stof lines that are causing the code to not run, as it does fine when i get rid of them

#

i just cannot seem to figure out why

vapid crown
#

sure, open a debugger and determine which value is causing stof to fail

minor scarab
#

i don't think i understand

drifting trench
#

here's the debugger feature tour link again, if you didn't see/read it before

minor scarab
#

give me a second

#

okay

#

i keep trying to run it by steps but it just

#

okay wait

#

i figured it out

#

i just don't see how this helps

woeful violetBOT
#

@minor scarab Has your question been resolved? If so, type !solved :)

vapid crown
#

I mean, if we know what value is causing the issue, that's a huge help shrug

minor scarab
#

yeah but i just don't see how running it step by step will tell me what value causes the crash

#

so far nothing seems out of the ordinary when debugging that way

#

got past the only uses of stof in the file

drifting trench
minor scarab
drifting trench
# minor scarab

so it's actual a std::invalid_argument "invalid stof argument", not out of range

#

check what _Str is there by hovering over it

minor scarab
drifting trench
minor scarab
drifting trench
#

there you go

#

the lines in the text file likely don't match up with how you're parsing them

minor scarab
#

oh my GOD it was

#

the dumbest mistake ever

#

i just realized what it was

#

i forgot to reset the vector assigner counter after every loop so after the first loop it just went haywire

#

it was so SIMPLE

#

!solved

woeful violetBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity

minor scarab
#

THANKS

drifting trench