Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need to open a .txt file in c++ and display all the numbers, one on each line

ID: 3640201 • Letter: I

Question

I need to open a .txt file in c++ and display all the numbers, one on each line and have it sorted from lowest number to highest number.

I have provided the numbers that are in the text file here:
22 44 6 19 7 88 1 6 42 2 8 2
11 9 61 44 39 33 3 23 2 23
16 8 66 4 97 3 55 7 18 55 1

Basically I need to figure out how to display each number on each line and have it sorted at the same time while it's being outputted. Please no C, only C++.

Explanation / Answer

#include #include #include #include #include using namespace std; int main() { vector nums; int newNum; ifstream theFile("file.txt"); //Open the file while(!theFile.eof()) //Read the input until end of file { theFile >> newNum; nums.push_back(newNum); //Put it in the vector } sort(nums.begin(), nums.end()); //Sort using std::sort for(int i = 0; i