Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7458761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T13:29:38+00:00 2026-05-29T13:29:38+00:00

so let’s say i have a vector, wich contains 4 elemens [string elements]. I

  • 0

so let’s say i have a vector, wich contains 4 elemens [string elements]. I need to loop through the vector first , then through each element , loop through an array of chars [vowels]
and to count how many vowels does that word contain.

    for(int i = 0; i < b.size(); i++) 
    {
      for(int j = 0; j < b[i].size(); j++) 
       {
         for(int v = 0 ; v < sizeof( vowels ) / sizeof( vowels[0] ); v++)
          if(//blabla)
       }
    }

so my question is, how can i loop through each word , i mean b[i][j] is the right way to do that?

if yes, this form , will work great? :

if(b[i][j] == vowels[v]) {
//blabla
}

thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T13:29:39+00:00Added an answer on May 29, 2026 at 1:29 pm

    A more advanced way to go about this, which you should take a look at if you’re serious about learning C++: don’t use indices and random access, use high-level STL functions. Consider:

    #include <algorithm>
    #include <iostream>
    #include <map>
    #include <numeric>
    #include <set>
    #include <string>
    #include <vector>
    
    bool is_vowel(char s) {
        static const char vowels[] = { 'a', 'e', 'i', 'o', 'u' };
        const char* vbegin = vowels;
        const char* vend = vowels + sizeof(vowels)/sizeof(char);
        return (std::find(vbegin, vend, s) != vend);
    }
    
    std::string::difference_type count_vowels(const std::string& s) {
        return std::count_if(s.begin(), s.end(), is_vowel);
    }
    
    template <class T> void printval(const T& obj) { std::cout << obj << std::endl; }
    
    int main() {
        std::vector<std::string> b;
        b.push_back("test");
        b.push_back("aeolian");
        b.push_back("Mxyzptlk");
    
        std::vector<int> counts(b.size());
        std::transform(b.begin(), b.end(), counts.begin(), count_vowels);
        std::for_each(counts.begin(), counts.end(), printval<int>);
    
        int total = std::accumulate(counts.begin(), counts.end(), 0);
        printval(total);
        return 0;
    }
    

    Where the loops you’ve written correspond roughly to these lines:

     std::transform(b.begin(), b.end(), counts.begin(), count_vowels);
     ..
     std::count_if(s.begin(), s.end(), is_vowel);
     ..
     std::find(vbegin, vend, s)
    

    This uses a high-level functional/generic programming idiom that C++ is not always elegant at pulling off IMO. But in this case it works fine.

    See Count no of vowels in a string for a rundown of solutions to part of the problem I think you’re trying to solve. You can see a variety of acceptable looping/iteration techniques on display there as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say you have a class called Customer, which contains the following fields: UserName
Let's say I have an facebook application running using the JS SDK. First user
Let's say I have some text as follows: do this, do that, then this,
let's say I have the following string: string s = A B C D
Let's say I have a main folder in my website named test which contains
Let's say I have the string: hello world; some random text; foo; How could
Let's say I have a javascript array with a bunch of elements (anywhere from
Let's say, if I need to assign an id to element with first name,
Let's say I have multiple requirements for a password. The first is that the
let's say that I have string: s = Tuple: and Tuple (stored in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.