• Register
0 votes

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 == ':')
       mytemp += x;
int main()
  ifstream inFile;
  string myday;
  int myminutes;
  double mytotal_callpay;
  //opens the .txt file
  //if the .txt file is openable, then printed to command myline.
  if (inFile.is_open())
     cout<<"Mydays Time Durations Cost"<<endl;
         istringstream split(myline);//splits each string into 3 separate strings (myday, mybeginning_time, myminutes)
               split >> myday;
               split >> mybeginning_time;
               split >> myminutes;
               **int time = stoi(mytemp);**
               time = time > 0 && time < 2400;
by (36.1k points)  

Your answer

Please note that all answers are moderated and will be deleted if they are:

>Not relavant to the programming or IT related
>Advertising campaigns or links to other sites
>Abusive content.

Kindly do not waste your time by posting non relevant content on Kodlogs.
Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.