Vogal find program output problem

Hello to everyone, I made this program that finds the vogals on a word. The program is finding the vogals but this line of code cout << word1 << "\n";, i pass each letter of a string (word) to each index of an array ( word1), is not working well, when I execut it the output that I'm counting on for exemple "flowers" but instead I get a weird combination of numbers and letters, 0x28fde0. Could someone explain me what this is? Im using CodeBlocks 12.11

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#include <string>

using namespace std;

int main(){

    string word;
    string vogals_in_word;
    string vogals[] = {"a", "e", "i", "o", "u"};
    int length_word;

    cin >> word;
    cout << word.length() << "\n";

    length_word = word.length();
    string word1[length_word];

    for(int i=0; i<length_word; i++){
            word1[i] = word[i];
            cout << word << "\n";

    }
    cout << word1 << "\n";
    cout << word << "\n";

    for(int i=0; i<5; i++){
            for(int j=0; j<length_word; j++){
                    if(word1[j] == vogals[i]){
                        vogals_in_word.append(word1[j] + ",");
                    }
            }
    }

    cout << "Vogals are: " << vogals_in_word;
}
Last edited on
Line 17: You've declared word1 as an array.
Line 24: You outputting the address of the array (the hex value you see).

There's really no need to put each letter into a separate string, since you can reference individual characters.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <string>

using namespace std;

int main()
{  string word;
    string vowels_in_word;
    const string vowels = "aeiou";

    cout << "Enter word: "; 
    cin >> word;

    for(int i=0; i<5; i++)
    {   for(int j=0; j<word.size(); j++)
        {   if (word[j] == vowels[i])
            {   vowels_in_word += word[j];
	 vowels_in_word += ",";
             }
        }
    }
    cout << "Vowels are: " << vowels_in_word << endl;
}


Hello, thanks for replying and for helping me. I search the net and saw that the name of the array is the address of the first element of the array! Thanks again
Last edited on
Topic archived. No new replies allowed.