vector of strings

hi all im trying to write this program that take a char array and outputs a vector string where each string contains one letter more than the previous one however, it should not contain any vowels. Prompt the user for the length of the initial string which must be 1,2 or 3 letters and the length of the final string which must be greater than the initial string length.

heres my program:

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

#include <iostream>
#include <vector>
#include <sstream>


using namespace std;
int main()
{
    char cPhrase[]="Alex, Mike and Nanzhu are the three TAs for this class.";


    stringstream buf(cPhrase);
    vector<string> cString;
    char delim = 'a';
    char delim1 = 'e';
    char delim2 = 'i';
    char delim3  = 'o';
    char delim4 = 'u';
    for(string word; getline(buf, word, delim);)
       cString.push_back(word-(delim-delim1-delim2-delim3-delim4));


    for(size_t i=0; i<cString.size(); i++)
       cout << '"' << cString[i] << "\" ";
return 0;
}




i am doing this but the compiler keeps giving me an error
closed account (j2NvC542)
Prompt the user for the length of the initial string which must be 1,2 or 3 letters and the length of the final string which must be greater than the initial string length.

What is the [length of the] "initial string"? It isn't cPhrase, is it? Same for "final string". And how can the final string be longer if it's the stripped initial string?

cString.push_back(word-(delim-delim1-delim2-delim3-delim4));
You can't subtract a char from a string. What you are doing is subtracting the integral values of the char variables. What was your goal on that line?

And could you please show how the output should look like, if it worked correctly? Like, an example what's in the vector at the end.

    lx
   , M
   k nd 
    Nnzh 
    r th
^^if the user inputs 2, 6 for example
can i use an if statement??
closed account (j2NvC542)
Sorry that I am so late, but this is what I did yesterday.
I still don't know what you need an input for, but maybe you can work with this.

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
#include <iostream>
#include <vector>
#include <sstream>


using namespace std;
int main()
{
    string Phrase ="Alex, Mike and Nanzhu are the three TAs for this class.";
    const string delim = "aeiou";


    vector<string> cString;
    string appending_char; // we need this, or the compiler will complain,
                           // that we want to append a char to a string.

    bool is_vowel;

    for (int i=0; i<Phrase.size(); ++i) {
        is_vowel = false;

        for (int j=0; j<delim.size(); ++j) {
            if (Phrase[i] == delim.at(j))
                is_vowel = true;
        }
        if (is_vowel == false) {
            appending_char = Phrase[i];
            cString.push_back(appending_char);
        }
    }


    for(size_t i=0; i<cString.size(); i++)
       cout << '"' << cString[i] << "\" ";
return 0;
}


If you have any questions, ask.
Last edited on
Topic archived. No new replies allowed.