Why am I having this error message from g++?
问题 Below is my code. It compiles fine in g++, but there is always this running time error: Segmentation fault (core dumped) Where am I wrong? #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; } } 回答1: You are looping