CPP   37

sort.cpp

Guest on 14th January 2022 10:37:34 AM

  1. #include<iostream>
  2. using std::cout; using std::endl;
  3. #include<string>
  4. using std::string;
  5.  
  6. // note you need algorithm and sort
  7. #include<algorithm>
  8. using std::sort;
  9.  
  10. /*
  11.   sort individual characters of a string
  12. */
  13.  
  14. int main (){
  15.   string my_str = "aebcd";
  16.   cout << "String was:"<<my_str;
  17.   sort(my_str.begin(), my_str.end());
  18.   cout << ", and sorted is:"<< my_str<<endl;
  19. }

Raw Paste


Login or Register to edit or fork this paste. It's free.