这是代码:
#include <iostream>
using namespace std;
int main( int argc, char *argv[])
{
int i;
// Display each command-line argument.
for( i = 1; i < argc; i++ )
cout << " argv[" << i << "] " << argv[i] << "\n";
}
如何按指针按字母顺序对输出进行排序?
答案 0 :(得分:2)
#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( i = 1; i < argc; i++ )
cout << " argv[" << i << "] " << argv[i] << "\n";
}