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

The Archive Base Latest Questions

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

Hey im validating a string. string getString(string q) { string input; do { cout

  • 0

Hey im validating a string.

string getString(string q)
{
    string input;

    do
    {
        cout << q.c_str() << endl;
        cin >> input;
    } while (!isalpha(input));

    return input;
}

When using while(!isalpha(input)); input gives that error.

Can anyone help me with this?

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

    The other answer describes what the problem is, but here’s a solution that makes use of algorithms from the standard library instead of writing your own (example requires C++11)

    bool all_alpha( std::string const& s )
    {
      return std::all_of( s.cbegin(), s.cend(), static_cast<int(*)(int)>(std::isalpha) );
    }
    

    The above function will return true only if all characters in the string are alphabetic. If you only want to disallow numeric characters, I’d use a slightly different function.

    bool any_digit( std::string const& s )
    {
      return std::any_of( s.cbegin(), s.cend(), static_cast<int(*)(int)>(std::isdigit) );
    }
    

    or

    bool no_digits( std::string const& s )
    {
      return std::none_of( s.cbegin(), s.cend(), static_cast<int(*)(int)>(std::isdigit) );
    }
    

    Use these functions to validate the input that you receive from the user.


    If you can’t use C++11 features, the functions can be modified to use std::find_if instead, and compare the return value of find_if to s.end() to determine success / failure.

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

Sidebar

Related Questions

Hey I'm trying to perform input validation in PHP to ensure that the stock
Hey, I'm using Levenshteins algorithm to get distance between source and target string. also
Hey guys I'm getting a pretty nasty redirect loop since I'm using a bootstrap
Hey I thought about writing a function that prompts me in certain situations (perl
Hey everyone I have a basic search function here that allows me to search
Hey guys I am making a terminal application using Swing and Apache Commons. I
I am using the gem 'geocoder'. I am trying to make an object that
I have a form with a fairly large amount of input that will also
Hey I'm using a HashMap to keep track of services and service-requests on a
Hey everyone, I'm using Virtual PC and working with a virtual hard disk (*.vhd)

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.