Answers for "how to sort string containing numbers in c++"

C++
0

how to sort string containing numbers in c++

#include <iostream>
#include <bits/stdc++.h> 
#include<string>
using namespace std; 
int main() {
   string s="4321";
   int a[s.length()];
  for(int i=0;i<s.length();i++){
    a[i]=s[i]-48;
   }
  sort(a,a+s.length());
for(int i=0;i<s.length();i++){
    cout<<a[i];
   }
    return 0;
}
Posted by: Guest on February-17-2021

Code answers related to "how to sort string containing numbers in c++"

Browse Popular Code Answers by Language