int main()
{
int noOfInput;
std::cin >> noOfInput;
try
{
std::getline(std::cin, line);
auto start = line.find_first_not_of(" ");
auto stop = line.find_first_of(" ", start);
int quantitiy = std::stoi(line.substr(start, stop - start));
}
catch (const std::logic_error & ex)
{
std::cout <<"Logic Error: " << ex.what() << std::endl;
}
}
Running the above code with the following input:
4
1 book at 14.49
1 shirt at 19.99
1 chocolate bar at 1.00
1 clearance chocolate bar at 2.00
I am getting exception just after entering my No of inputs:
Logic Error: basic_string::substr: __pos (which is 18446744073709551615) > this->size() (which is 0)
What's wrong with my code?