hi all.
Recently, try to learn C + +, and I am doing some exercises in the book on which study.
below, I have tried to create an algorithm that reads a string and separates the consonants from the vowels, creating two different strings.
the algorithm is compiled, but when you run the program, it happens that running the first "for" loop, although the condition "if", do not enter any letter in the string, and the third for loop ", reverses the consonants with vowels, or law more letters at the same time.
In a previous post, I was advised to use the std :: string :: reserve, but not having yet been evaluated, I can not place it.
thanks for your attention.
#include <iostream>
#include <string>
using namespace std;
int main()
{
string a="aeiou";
string b="bcdfghjklmnpqrstvwxyz";
string kk[30]; //nuova stringa consonanti creata
string ww[30]; //nuova stringa vocali creata
string d;
int c=-1; //contatore per indice stringa consonanti
int v=-1; //contatore per indice stringa vocali
getline(cin,d);
int s=d.length();
for (int i=0;i<s;i++)
{
int z=b.find(d[i],i); //cerca d[i] in b
cout<<"i= "<<i<<" z= "<<z<<'\n';
if (z>0) // se z>0 vuol dire che d[i] รจ una consonante
{
cin.ignore();
string k[30]; //elemento creatore della nuova stringa consonanti
c=c+1; // contatore consonanti
cout<<" c= "<< c <<'\n';
k[c]=d.substr(i,i); //estrae la consonante iesima e l'assegna al vettore k
cout<<" k["<<c<<"]= "<< k[c]<<'\n';
kk[c]=kk[c]+k[c]; // creazione della stringa consonanti
cout <<" kk["<<c<<"]= "<< kk[c]<<'\n';
}
else
{
if (z<0)
cin.ignore();
v=v+1;
string w[30]; //elemento creatore della nuova stringa vocali