I want to create a program that will transform the same words into one. I have a problem with code where I used "while". If I put "if" instead of "while" its working, but not as right as I want, so I need to use "while", but its not working correctly. Its compiling, but not working after inputting the string a.
#include <iostream>
using namespace std;
int main ( ) {
string a;
cout << "Введите string a: ";
getline(cin,a);
for (int i = 0; i < a.length(); i++) {
while (a[i]=a[i+1]) {
for (int z = i; z < a.length(); z++) {
a[z]=a[z+1];
}
}
}
cout << endl << a << endl;
}
Aucun commentaire:
Enregistrer un commentaire