I already tried with other posts on this site, but it didn't work. I'm hoping you could help me. The problem is to erase all the vowels in the given string, then transform it to lowercase and finally to insert the '.' character before each consonant. This last one is the one that is giving me troubles.
#include <iostream> #include <cstdio> #include <ctype.h> #include <string> using namespace std; string cad1; char vowels[] = { 'A', 'O', 'Y', 'E', 'U', 'I', 'a', 'o', 'y', 'e', 'u', 'i' }; int size = sizeof(vowels) / sizeof(vowels[0]); string ToLowerCase(string text) { for (int i = 0; i < text.length(); i++) { char c = text[i]; if ((c >= 65) && (c <= 90)) { text[i] |= 0x20; } } return text; } int main() { cin >> cad1; for (int i = 0; cad1[i] != '\0'; i++) { for (int j = 0; j < size; j++) { if (cad1[i] == vowels[j]) { cad1.erase(cad1.begin() + i); } } for (int j = 0; cad1[j] != '\0'; j++) { cad1[j] = tolower(cad1[j]); } cad1 += "."; /* for (int k = 0; cad1[k] != '\0'; k++) { if (k % 2 == 0) { cad1.insert(k, 1, '.'); } } */ } cout << cad1 << endl; cin.get(); }
std::string? I see you included it.cad1. Removecad1 += ".";too.vowelarray, insert the character.