• Register
0 votes
60 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;
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
>Spam
>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.
...