• Register
0 votes
423 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 dealing with stoi is present towards the bottom of the code.

Please find below my code :

 #include "LongDistanceCalls.h"
 #include <iostream>
 #include <string>
 #include <fstream>
 #include <sstream>
 #include <algorithm>
 #include <iterator>
using namespace std;  
string myline;
string mytemp = "";
string mybeginning_time;
void convertTimeintoInt(string mybeginning_time)
{
  for(char x : mybeginning_time)
  {
     if(x == ':')
            continue;
    else
       mytemp += x;
  }
}
int main()
{
  ifstream inFile;
  string myday;
  int myminutes;
  double mytotal_callpay;
  //opens the .txt file
  inFile.open("MyCallRecords.txt");
  //if the .txt file is openable, then printed to command myline.
  if (inFile.is_open())
  {
     cout<<"Mydays Time Durations Cost"<<endl;
     while(getmyline(inFile,myline))
     {
         istringstream split(myline);//splits each string into 3 separate strings (myday, mybeginning_time, myminutes)
        while(split)
             {
               split >> myday;
               split >> mybeginning_time;
               split >> myminutes;
               **int time = stoi(mytemp);**
               time = time > 0 && time < 2400;
9 7 4
38,600 points

Please log in or register to answer this question.

Related questions

0 votes
1 answer 15 views
15 views
Problem: I need your help in solving this error: Terminating with uncaught exception of type std::invalid_argument: stoi: no conversion
asked Mar 14 Wafa Abu Yousef 6.1k points
0 votes
1 answer 2.3K views
2.3K 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
1 answer 38 views
38 views
Problem: is this a common situation with anybody? Terminate called after throwing an instance of 'std::invalid_argument' what(): stoi.
asked Mar 6 Wafa Abu Yousef 6.1k points
1 vote
1 answer 3.2K views
3.2K 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 [ ... 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?
asked Dec 12, 2019 alecxe 7.5k points
1 vote
1 answer 23 views
23 views
Problem: I get this error everytime I write a function that recieves strings. Can someone please help me out with this?
asked Mar 26 prerna32 130 points
0 votes
1 answer 7 views
7 views
Problem: I'm trying to read strings from a file and initializing objects (from type "Movimentacao") with this strings and putting these objects into a vector. To do that, I have to transform some strings into ints but when I try to execute the program, it shows this error: terminate ... sig = sigla[0]; Movimentacao M(stoi(dia), stoi(mes), stoi(ano), desc, sig, stod(val)); movi.push_back(M); }
asked Apr 26 ochena 22.1k points
0 votes
1 answer 13 views
13 views
Problem: gives me the compile error: error: 'stoi' is not a member of 'std' int myint = std::stoi(test); Why is it not compiling?
asked Mar 22 ummesalma 29.2k points
0 votes
1 answer 5 views
5 views
Problem: Why cannot use object of type std class as an array. What created the error?
asked Mar 31 zayed1 58.7k points
0 votes
1 answer 3 views
3 views
Problem: How to fix 'NSUnknownKeyException', reason: &hellip; this class is not key value coding-compliant for the key X" error? while i was setting up a userdefualt integer and when i segue to the page the app crashes. It shows the appDelegate with it says " Thread 1: ... ") as! NSInteger! fiveth1.text = NSString(format: "Fiveth: %i", fiveth) as String } fiveth1.text = "\(Fiveth)" } iosswift3
asked Apr 17 ochena 22.1k points
0 votes
1 answer 3 views
3 views
Problem: i don&rsquo;t understand this problem. please help? libc++abi.dylib: terminating with uncaught exception of type nsexception
asked Apr 9 Rohit kr 17.5k points