sortingC ++string的字符
如果我有一个string有一个内置函数来sorting字符,或者我会写我自己的?
例如:
string word = "dabc"; 我想改变它,所以:
 string sortedWord = "abcd"; 
也许使用char是一个更好的select? 我将如何在C ++中做到这一点?
 标准库中有一个sortingalgorithm ,在头文件<algorithm> 。 它sorting,所以如果你做了以下,你的原始单词将被sorting。 
 std::sort(word.begin(), word.end()); 
如果您不想丢失原件,请先复印一份。
 std::string sortedWord = word; std::sort(sortedWord.begin(), sortedWord.end()); 
 std::sort(str.begin(), str.end()); 
看到这里
 您必须包含在c ++中的标准模板库的 algorithm头文件中的sort函数。 
用法 :std :: sort(str.begin(),str.end());
 #include <iostream> #include <algorithm> // this header is required for std::sort to work int main() { std::string s = "dacb"; std::sort(s.begin(), s.end()); std::cout << s << std::endl; return 0; } 
OUTPUT:
abcd
你可以使用sort()函数。 sort()存在于algorithm头文件中
  #include<bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); string str = "sharlock"; sort(str.begin(), str.end()); cout<<str<<endl; return 0; } 
输出:
achklors
 #include<bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); string str = "sharlock"; sort(str.begin(), str.end()); cout<<str<<endl; return 0; } 
如何执行内部请解释逻辑