algorithm - How to sort command line arguments alphabetically in C++ by pointers -
this code:
#include <iostream> using namespace std; int main( int argc, char *argv[]) { int i; // display each command-line argument. for( = 1; < argc; i++ ) cout << " argv[" << << "] " << argv[i] << "\n"; }
how can sort ouput alphabetically pointers?
#include <iostream> #include <algorithm> using namespace std; bool mycmp(const string& a, const string &b) { return (a<=b); } int main( int argc, char *argv[]) { int i; sort(argv+1, argv + argc, mycmp); for( = 1; < argc; i++ ) cout << " argv[" << << "] " << argv[i] << "\n"; }
Comments
Post a Comment