下面是我的代码。它在 g++ 中编译得很好,但总是有这个运行时错误:Segmentation fault (core dumped)
我哪里错了?
#include<iostream>
#include<string>
using namespace std;
void sort_string(string x){
for (int i=0;x.size();i++){
for(int j=i;x.size();j++){
char temp = x[i];
if (temp > x[j]){
x[j]=temp;
x[i]=x[j];
}
}
}
}
int main(){
string words;
cin >> words;
while (words != " "){
cout << words << " ";
sort_string(words);
cout << words << endl;
}
}