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 7187437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:50:42+00:00 2026-05-28T18:50:42+00:00

I have a vector of strings example: dedf eedf fedf hedf I want to

  • 0

I have a vector of strings
example:
dedf
eedf
fedf
hedf

I want to go through the list and count how many times each letter appears

so for example the letter
d appears 5 times
e appears 5 times
f appears 5 times
h appears 1 time

I don’t have no code so far but I’m trying to see how I can do this with logic first.

I’m trying to code but don’t know where to start.

I was thinking I can store each letter into a string.
string would be {dedfeedffedfhedf}

Then take the string and count each time the letter is in that string
but this is where I’m having a problem. Any thoughts?

Any suggestions would also be appreciated.

Thank You

  • 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-28T18:50:43+00:00Added an answer on May 28, 2026 at 6:50 pm

    You can have an array for holding the counts of each letter. If we’re assuming just the alphabet, you’ll have an array of 26 elements (likely ints), all initialized to 0. Then you can go through each string, and each time you encounter a character, you increment that count.

    //let's call your vector of strings stringvec
    int counts[26];
    
    //initialize counts to 0
    
    //go through each string in the vector
    for (int i = 0; i < stringvec.size(); i++) {
        //get current string
        string curstr = stringvec[i];
    
        //for each letter in the string
        for (int j = 0; j < curstr.size(); j++) {
            //curstr[j] is a character at position j in the string
            //subtracting 'a' from it will give you the position in relation to 'a' in ASCII, so a character 'a' = 0, 'b' = 1, 'c' = 2, and so on...
            counts[curstr[j] - 'a']++;
        }
    }
    

    And then you do whatever you want with the counts.

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

Sidebar

Related Questions

I'm wondering if it's possible if you have, for example, a vector<string> and a
I have a std::vector<uint8_t> that contains strings at specific offsets. Here's a shortened dump:
I have some data structures: all_unordered_m is a big vector containing all the strings
I have a vector that I want to insert into a set . This
I have a vector of strings. Check out my vector, it's awesome : >
Example, I have billions of short phrases, and I want to clusters of them
A have a vector of strings in c++: vector<string> myVect = {A, A, A,
I have a number of vectors of strings each containing dates. As a simple
I have a vector of Key-Value pairs, where each Key-Value pair is also tagged
I have made a string vector vector<string> actor_; and then added elements in it

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.