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

Feb 12, 2020 at 8:23pm
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 Feb 13, 2020 at 1:56am
Feb 12, 2020 at 8:29pm
Get the sentence.
Split it into individual words.
Look at first letter of each word.
If the word begins with a vowel, output it.
Feb 12, 2020 at 8:29pm
Given a single word, can you show how to tell if it starts with a vowel?
Feb 12, 2020 at 10:59pm
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 Feb 13, 2020 at 8:54am
Topic archived. No new replies allowed.