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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:11:29+00:00 2026-06-10T04:11:29+00:00

Ok guys this problem has been bugging me all day and I cant seem

  • 0

Ok guys this problem has been bugging me all day and I cant seem find a solution. I know Its a long post but I would be very grateful for any help you can offer.
I am working on a chatbot program that reads in from a .dat file to populate a library of keywords. Taking an object orientated approach I defined a class called “Keyword”, the class definition is shown below:

class Keyword
{
public:   
    //_Word holds keyword 
    vector<string> _Word;
    //_Resp holds strings of responses
    vector<string> _Resp;
    //_Antymn holds words that are the opposite to keyword
    vector<string> _Antymn;

    // Constructor
    Keyword()
    {
        // Clears members when new instance created
        _Word.clear();
        _Resp.clear();
        _Antymn.clear();
    }
};

Therefore every time a new keyword is found in the .dat file, a new instance of the class keyword must be created. To store all these instances of keyword I create another vector but this time of type Keyword and call it library:

typedef vector<Keyword> Lib;
Lib library;// this is the same as saying vector<Keyword> library

Now this is the problem I have: After a user inputs a string I need to check if that string contains a keyword from the library i.e. I need to see if the string in _Word appears in the user input. Looking at it from a hierarchy of vectors you have:

The top level --> libary //*starting point
                 --> Keyword
                    --> _Word
                      -->"A single string" <-- I want to reference this one
                    --> _Resp
                      -->"Many strings"
                    --> _Antymn
                      -->"Many strings"

Phew! I hope that made sense.
This is the code I started to write:

size_t User::findKeyword(Lib *Library)
{
    size_t found;
    int count = 0;

    for(count = 0; count<Library->size(); count++)
    {
      found = _Input.find(Library->at(count)); // this line needs to reference _Word from each keyword instance within library
      if(found!= string.npos)
        return found;
    }

    return 0;
}

I have also tried to use the “operator[]” method but that doesnt seem to do what I want either.
Does anyone have any idea ? I would be very suprised if it couldn’t be done. Thank you in advance.

  • 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-06-10T04:11:30+00:00Added an answer on June 10, 2026 at 4:11 am

    You have to change your code to this:

    for(count = 0; count<Library->size(); count++)
    {
        for(int j = 0; j < Library->at(count)._Word.size(); ++j){
            found = _Input.find(Library->at(count)._Word[j]);
                                                  ^^^^^^^^^
            if(found!= string.npos)
                 return found;
        }
    }
    

    in order to access the member variable and to iterate through your vector of strings. Library->at(count) is an object of class the Keyword.
    I assume that _Input.find() takes a string as argument.

    If your Keyword instance stores just one keyword, you might as well change it to string _Word, so that you wold not need the second loop.

    for(count = 0; count<Library->size(); count++)
    {
        found = _Input.find(Library->at(count)._Word);
        if(found!= string.npos)
            return found;
    }
    

    And to enforce the other comments: you should not use the preliminary _-underscore in your variable names since they are reserved by the implementation.

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

Sidebar

Related Questions

There's this problem that has been bugging me all day now, and I hoped
hey guys having this really simple problem but cant seem to figure out have
Okay guys, basically the problem I'm having is this. I've been assigned to write
This has been driving me mad someone help coz i don't seem to see
EDIT: Sorry Guys, This has been resolved The comment to check the inline style
OK guys I can't find a solution anywhere for my problem, and I hope
This problem with calling up the font that has been declared at the start
Ok guys I am completely aware this question has been asked on several sites
I know this question has been asked a bit before. But looking around I
Hi guys I am sure this question has been asked already but I am

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.