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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:13:10+00:00 2026-05-31T09:13:10+00:00

I have got some code that gets the most frequent words and puts them

  • 0

I have got some code that gets the most frequent words and puts them into a vector. I then sort the vector into numerical order and all this works fine. I then try to resize the vector to 10 so I can get the top ten that I want to sort by word.

I think the problem lies with part of my struct but i am not to sure here is the code i am using.

struct wordFreq
{
    string word;
    int count;

    wordFreq(string str, int c): word(str),count(c) { }
}; 

words.resize(10);

Any help will be appreciated.

  • 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-31T09:13:12+00:00Added an answer on May 31, 2026 at 9:13 am

    When resizing the vector, the function resize needs to know the value for the new elements. Therefore, the call

    words.resize(10);
    

    includes a default argument of the form wordFreq(), which is invalid in your case, since the class wordFreq doesn’t have a default constructor.

    If no new elements are being created, use erase instead of resize.

    words.erase(words.begin() + 10, words.end());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following question: I got some code that gets called when an
I have got a piece of code, that should countdown some number (in this
I have got some code to load an assembly and get all types, which
I have got some javascript code and I'd like to convert this to C#.
I've got some entities which have decimal properties on them. These entities' properties are
I've got some Columns in a DataGridView that have their Binding property set to
I've got some 3rd party beans that have method signatures that fit quite well
I have some VB.NET code that creates a TransactionScope instance: LoggingUtility.LogDebug(UpdateCallTable, SatComCallDataImporter, About to
I have got an ASP page that does some back-end processing. It calls a
I've got some code that needs to scan through a hierarchical database schema, looking

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.