• Register
1 vote
1.9k views

Problem :

My stoi function is crashing the program with the error message as below :

"****@****:~> g++ -std=c++0x m1.cpp stimulation.h stims.h Task.h exoskeleton.h ARAIG_Sensors.h Profile.h
ARAIG_Sensors.h:1:9: warning: #pragma once in main file [enabled by default]
Profile.h:1:9: warning: #pragma once in main file [enabled by default]
*****@****:~> a.out StimulationConfig.csv TaskConfiguration.csv SampleProfileConfig.csv SampleOutput.txt
First : a.out
Second : StimulationConfig.csv
terminate called after throwing an instance of 'std::invalid_argument'
what():  stoi
Aborted

I am unable to know why is there the instance being passed to the method but it is still returning the above error. Can somebody help me in resolving the issue?

6 5 3
7,540 points

1 Answer

0 votes

Solution :

It clearly means that you are giving std::stoi() bad input, that’s why it is throwing the std::invalid_argument exception that you are unfortunately not catching.

std::stoi, std::stol, std::stoll:

Exceptions as below :

· std::invalid_argument : Thrown if no conversion could be performed

· std::out_of_range Thrown if the converted value is out of the range of the result type or if the underlying function std::strtol or std::strtoll is trying to set errno to ERANGE.

std::terminate:

The std::terminate() is called by the C++ runtime when the exception handling fails for the below reason:

If an exception is thrown and not caught :

Here you need to cross-check your input string values that you are converting to integers. As they do not represent the integers.

9 7 4
38,600 points

Related questions

0 votes
2 answers 706 views
706 views
Problem : I have written the code to perform the following tasks in the order in which they are stated: 1. Read the input file and count the number of entries in it 2. Create the array of appropriate size (size equal to number of entries) 3. Go back to the ... method, but I am unable to figure out how to solve problem in this specific situation. Please Note: I am working on a Linux computer.
asked Dec 4, 2019 alecxe 7.5k points
1 vote
1 answer 146 views
146 views
Problem : I am a Computer Science Student. I am trying to learn the C++ programming. I want to execute a very simple averaging code written by me but I always face below error: Terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: ... larger than 0? So I am confused because of above error. Can some expert in C++ guide me in fixing above error for me.
asked May 14 Martin K 6.6k points
1 vote
1 answer 772 views
772 views
Problem : I am literally trying to start learning C++, and I have written very simple code in C++ as follows for your reference: string mySong(string songlist[], int songnum) { for (i = 0; i < songnum; i++) { output += songlist[i]; output += bone1; ... available answers make sense with what I know about programming so far. So I am looking for the pin point solution to my above C++ related error.
asked May 13 Martin K 6.6k points
0 votes
1 answer 1.5K views
1.5K views
Problem : I want to convert the string into an int by using stoi, however for some unknown reason it is giving me an error and giving me following message: "libc++abi.dylib: terminating with uncaught exception of type std::invalid_argument: stoi: no conversion" The myline which is ... ; split >> mybeginning_time; split >> myminutes; **int time = stoi(mytemp);** time = time > 0 && time < 2400;
asked Dec 5, 2019 alecxe 7.5k points
0 votes
0 answers 304 views
304 views
Problem : I want to convert the string into an int by using stoi, however for some unknown reason it is giving me an error and giving me following message: "libc++abi.dylib: terminating with uncaught exception of type std::invalid_argument: stoi: no conversion" The myline which is ... ; split >> mybeginning_time; split >> myminutes; **int time = stoi(mytemp);** time = time > 0 && time < 2400;
asked Dec 5, 2019 AbhijitJ 38.6k points