pastebin - collaborative debugging tool
rovema.kpaste.net RSS


vector sort demo 001
Posted by Anonymous on Tue 19th Nov 2024 13:24
raw | new post

  1. #include <algorithm>
  2. #include <vector>
  3. #include <iostream>
  4.  
  5. static
  6. bool comp_string(std::string &a, std::string &b)
  7. {
  8.     return (std::stoi(a) < std::stoi(b));
  9. }
  10.  
  11. int main(int ac, char *av[])
  12. {
  13.     std::vector<std::string> v1{ "13", "17", "1", "2", "3", "5", "7", "11" };
  14.  
  15.     std::sort(v1.begin(), v1.end(), comp_string);
  16.  
  17.     std::cout << "test results:" << std::endl;
  18.  
  19.     for (auto x : v1)
  20.         std::cout << x << std::endl;
  21.  
  22.     return EXIT_SUCCESS;
  23. }

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at