Sorting a vector

This is an exercise for my final exam.


Create a character array that contains a sentence (with punctuation) that has at least 6 words (it can be longer). Store your sentence in the following format:

char cPhrase[]={'I',' ','l','o','v','e',' ','e','a','t','i','n','g',' ',

'a','l','l',' ','k','i','n','d','s',' ','o','f',' ','d','e','s','s','e','r','t','s','.','\0'};

Then create a vector of strings where the strings are determined by a letter of the user's choosing. For example if the user chose the letter "e" your program should create and print the following strings:

"I love", "e", "ating all kinds of de", "sse", "rts."

Your program should work even if the character array changes.


So I have this so far:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main ()
 {
char cPhrase[]=		{	'I',' ','l','o','v','e',' ','e','a','t','i','n','g',' ',
						'a','l','l',' ','k','i','n','d','s',' ','o','f',' ','d',
						'e','s','s','e','r','t','s','.','\0'
					};
vector<string>a;
a.push_back(cPhrase);
for (unsigned int i = 0; i < a.size(); i++)
{
	cout << a[i] << endl;
}

return 1;
}

Which is depressingly simple. I've tried for about two hours to filter it in different ways, but I haven't come anywhere close. My number one issue seems to be defining a character to stop the loop. Basically, my question is, how do I define a character so that i <= e becomes the stop point for the current output?
So I found this:

http://www.cplusplus.com/forum/beginner/75974/

Even from July of this year. Probably taking a course sourced from the same text as the course I am taking.

Unfortunately, we haven't covered getline or regax so i don't understand those two...
dont know what i<=e is for, what you need is
- a for loop to run through all the characters of the char array
- an if statement where you check cPhrase[i] == 'e'
Topic archived. No new replies allowed.