Title: A series of numbers in a file, separated by commas, with bits 23.34,4242.42,343 ......., requiring reading and sorting;
Summarized before, still have to look at it and pay attention to it;
https://www.cnblogs.com/songlinxuan/p/12370059.html
Code:
#include<iostream> #include<fstream> #include<string> #include<algorithm> #include<vector> using namespace std; string path = "C:\\Users\\Reality\\Desktop\\random\\test.txt"; vector<double>vec; int main() { fstream fin; string s; fin.open(path, ios::in); while (getline(fin,s,',')) { double d = stod(s); vec.push_back(d); } sort(vec.begin(), vec.end()); for (int i = 0; i < vec.size(); i++) { cout << vec[i] << endl; } }