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

  • Home
  • SEARCH
  • 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 8767155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:44:16+00:00 2026-06-13T16:44:16+00:00

Im trying to have the boolean found_word to return true if it finds the

  • 0

Im trying to have the boolean found_word to return true if it finds the word/character and false if it doesn’t, but it returns true ALWAYS, no matter what I write in the text. The loop itself works, already tried that. IOStream and string are included.

while(timestorun){
    found_word = text.find("khgdawjugfdjhawbdjkhsadgawkdsa");

    if(found_word){
        cout << "FOUND!!!" << endl;
    }
    else if(!found_word){
        cout << "Found problem!!!!!"<< endl;
    }
    timestorun--;
}

Any suggestions?

  • 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-13T16:44:19+00:00Added an answer on June 13, 2026 at 4:44 pm

    You’re supposed to compare with npos. find doesn’t return a boolean value.

    found_word = text.find("khgdawjugfdjhawbdjkhsadgawkdsa") != std::string::npos;
    

    0, which is false, would only be returned if the substring was found at index 0.

    Also, your second condition is redundant – if found_word is false, I personally guarantee !found_word will be true.

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

Sidebar

Related Questions

I am trying to have a function return a boolean and an address in
I have been trying to use/save the boolean value of a checkbox in other
Trying to have my PHP script return some SQL table queries. Here's my script
I am trying to construct method which returns a boolean: public boolean isStringValid(String s){
I have a BOOLEAN type in a MySQL table (TINYINT(1)) and I'm trying to
Afternoon, I am trying have an HTML file containing a frameset which contains two
I have trying to learn MVC4 Web API. I am running my project from
I have a cache directory I'm trying to have ignored by git which lives
I'm trying to have images fade in with css3 once they're loaded. The problem
I am trying to have a table like this: Manager Expert Adminis. Staff Dept

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.