I am trying to read an txt file row by row and write those rows into a vector Each row has an integer value like 1586794757328642
My code is below
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
int main ()
{
std::ifstream file("input.txt");
std::string str;
std::vector<int> myVect;
while (std::getline(file, str)) {
std::cout << str << "\n";
int myint = std::stoi(str);
myVect.push_back(myint);
}
}
However, I got the following error:
1586794757328642
terminate called after throwing an instance of 'std::out_of_range'
what(): stoi
Aborted (core dumped)
What am I missing?