• Register
0 votes
339 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 1.7K views
1.7K 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
1 vote
1 answer 2.3K views
2.3K 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
0 votes
1 answer 18 views
0 votes
1 answer 16 views
0 votes
1 answer 15 views
0 votes
1 answer 48 views
48 views
Problem : I want to compile my code to test my function to read and print the data file, but I get the compiling error that I don't understand as follows "Error: expected constructor, destructor, or type conversion before ';' token".
asked Jan 24, 2020 jwilliam 3.9k points
1 vote
1 answer 213 views
213 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, 2020 Martin K 6.6k points
1 vote
1 answer 1K views
1K 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, 2020 Martin K 6.6k points
1 vote
1 answer 22 views
22 views
Problem: I am a new student of c++ programming. I am taking an online-based course to learn it. I&rsquo;ve written a pretty simple program that adds two numbers through a function. I am attaching my code snippet below, please have a look: int promptNumber() { int n; std: ... ;t run the program. I keep getting an error: cout is not a member of std Could any of you please shed some light on this?
asked Mar 31, 2020 Gavin 15.3k points
0 votes
2 answers 791 views
791 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