Learn C++ Online

Streams and input validation (part 2)

On this page
This lesson contains approximately 26 minutes of video content.

Trying to recover from a format read error

Actually recovering from format read errors

Recap: recovering from format read errors

In this exercise, you will implement the function get_ints_from_file(std::string file_name) which will return an std::vector<int> containing all integer values present in the file file_name. Should you encounter a formatted read failure, you must recover and continue reading integer values from the file.

Here's an example of one of our test file's contents:

1 2 a 9 8

Note: We are unable to provide you with "Run" functionality on this exercise. Therefore, we highly recommend that you work on this problem inside your CS 128 development environment and submit your solution code here to verify its correctness.

#ifndef SOLUTION_HPP #define SOLUTION_HPP #endif
#include "solution.hpp"
> Click Run to compile and run your code.