****Extract Word Starting With Vowels From A String****

So I Need To Extract All The Words That Starts With A Vowel From A User Given Sentence And Print Them....
I can't build a code...(can't Think Anything about the code Algorithm)
Help Will Be Appreciated...
Thank You
Last edited on
Get the sentence.
Split it into individual words.
Look at first letter of each word.
If the word begins with a vowel, output it.
Given a single word, can you show how to tell if it starts with a vowel?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <iterator>
using namespace std;

const string vowels{ "aeiouAEIOU" };

int main()
{
   istringstream in( "So I Need To Extract All The Words That Starts With A Vowel From A User Given Sentence And Print Them" );
   copy_if( istream_iterator<string>{ in }, {}, ostream_iterator<string>{ cout, " " }, []( string s ){ return vowels.find( s[0] ) != string::npos; } );
}



or just
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <sstream>
#include <string>
using namespace std;

const string vowels{ "aeiouAEIOU" };

int main()
{
   istringstream in( "So I Need To Extract All The Words That Starts With A Vowel From A User Given Sentence And Print Them" );
   for ( string s; in >> s; ) if ( vowels.find( s[0] ) != string::npos ) cout << s << ' ';
}
Last edited on
Topic archived. No new replies allowed.