#include <iostream> #include <fstream> #include <string> #include <cstdlib> #include <vector> #include <algorithm> #include <iterator> #include <functional> using namespace std; using namespace std::placeholders; struct CoreUser { string user; double cost; }; istream& operator>>(istream& in, CoreUser& core) { in >> core.user >> core.cost; return in; } struct SortUser { bool operator()(const CoreUser& u1, const CoreUser& u2) { return u1.cost < u2.cost; } }; int main(int argc, char **argv) { if (argc < 2) return EXIT_FAILURE; ifstream in{argv[1]}; if (!in) return EXIT_FAILURE; CoreUser u; vector<CoreUser> v; while (in >> u) { v.push_back(u); } // type your code bellow. vector<CoreUser>::iterator ite = v.begin(); for(;ite < v.end();ite++){ if((*ite).cost < 24.0){ v.erase(ite); } } SortUser sortuser; sort(v.begin(), v.end(), sortuser); for(int i = 0;i < v.size();i++) cout<<v[i].user<<" "<<v[i].cost<<endl; in.close(); }
The interpretation of the int main (int argc, char * argv []) in the parameters and argv arg
With a parameter of the main functions, such as main (int argc, char * argv [], char ** env), is UNIX, Linux, and Mac OS operating system, C / C ++ main function standard wording, and is the origin purest The main function of writing.
argc, argv specific meaning:
argc: (argument count) int type argc, commands sent to the main function of the number of line parameters to run statistical procedures, the default value is 1 in VS.
argv: (argument vector) char * type the argv [], an array of strings, used to store a pointer to an array of string parameters, each element pointing to a parameter.
argv [0]: pointing running full path name
argv [1]: The first point to a string in the DOS command line execution program name
argv [2]: after the execution of the program name points to the second string
argv [3]: after the execution of the program name pointing to third string
argv [argv]: is NULL
argv [0] Representative 123.exe argv [1] in the program representative of total.txt
There are two methods to import total.txt
1.cmd ---demo.exe total.txt
2.>g++ -std=c++11 demo.cpp -o 123.exe ----- >dir ---- >123.exe total.txt