Attached is a text file containing lots of randomly generated numbers in no particular order. Write a program that can open that file, sort the numbers from least to greatest, and display them in sorted order on the screen.
The name of the text file is; numbers_fall2020.txt
Please solve using C++
Thanks!
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
ifstream file("data.txt"); // open a file stream
vector<int> arr; // declear a vector
int x;
while(file>>x){ // read till the end of file
arr.push_back(x);
}
sort(arr.begin(),arr.end()); // sort the vector
for(int val:arr)cout<<val<<endl; // display to stdout
}
Get Answers For Free
Most questions answered within 1 hours.