fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5. using namespace std;
  6.  
  7. int main() {
  8. vector<string> a = {"1.0", "2.0", "3.0", "9.0", "10.0"};
  9. sort(a.begin(), a.end());
  10. for (auto &s : a)
  11. cout << s << " ";
  12. cout << endl;
  13. sort(
  14. a.begin()
  15. , a.end()
  16. , [](const string &lhs, const string &rhs) -> bool {
  17. return stod(lhs) < stod(rhs);
  18. }
  19. );
  20. for (auto &s : a)
  21. cout << s << " ";
  22. cout << endl;
  23. return 0;
  24. }
Success #stdin #stdout 0s 3420KB
stdin
Standard input is empty
stdout
1.0 10.0 2.0 3.0 9.0 
1.0 2.0 3.0 9.0 10.0