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

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -