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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:06:49+00:00 2026-06-15T08:06:49+00:00

Hey im trying to validate a string. Basically what i want it to do

  • 0

Hey im trying to validate a string. Basically what i want it to do is prevent the user from entering anything other than a string. Here is my code:

**getString**

string getString(string str)
{
    string input;
    do
    {
        cout << str.c_str() << endl;
        cin >> input;
    }
    while(!isalpha(input));
    return input;
}

Errors

Error   2   error LNK2019: unresolved external symbol "public: bool __thiscall Validator::getString(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?getString@Validator@@QAE_NV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: void __thiscall Player::information(void)" (?information@Player@@QAEXXZ)    C:\Users\Conor\Documents\College\DKIT - Year 2 - Repeat\DKIT - Year 2 - Semester 1 - Repeat\Games Programming\MaroonedCA2\MaroonedCA2\Player.obj    MaroonedCA2
Error   3   error LNK1120: 1 unresolved externals   C:\Users\Conor\Documents\College\DKIT - Year 2 - Repeat\DKIT - Year 2 - Semester 1 - Repeat\Games Programming\MaroonedCA2\Debug\MaroonedCA2.exe MaroonedCA2
    4   IntelliSense: no suitable conversion function from "std::string" to "int" exists    c:\Users\Conor\Documents\College\DKIT - Year 2 - Repeat\DKIT - Year 2 - Semester 1 - Repeat\Games Programming\MaroonedCA2\MaroonedCA2\Validator.cpp 72  17  MaroonedCA2

Main

cout << "What is your name ?\n";
    name = validator.getString();<------This skips.

    cout << "\nWhat is your age? ";
    age = validator.getNum();

    string character = "What is your sex M/F?";
    sex = validator.getChar(character);


    cout <<"Name:\n"<< name<<" Age:\n" << age<< " Sex:\n"<< sex <<"\n";

New getString function.

string Validator :: getString()
{
   string input;
    do 
    {
    } 
    while (
    std::find_if_not( 
        std::begin(input), //from beginning
        std::end(input), //to end
        isalpha //check for non-alpha characters
    ) != std::end(input) //continue if non-alpha character is found
);
    return input;
}
  • 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-15T08:06:51+00:00Added an answer on June 15, 2026 at 8:06 am

    The first problem described is that this function belongs to a class, but you forgot to specify that:

    string Validator::getString(string str)
           ^^^^^^^^^^^
    

    Next, isalpha takes an int (due to C reasons), and, as far as I know, there is no version for std::string. You can, however, use standard algorithms to do this:

    do {
        ...
    } while (
        std::find_if_not( 
            std::begin(input), //from beginning
            std::end(input), //to end
            isalpha //check for non-alpha characters
        ) != std::end(input) //continue if non-alpha character is found
    );
    

    This find_if_not call will search through the string and check if any non-alpha characters are found by comparing the return value to the ending iterator of the string. If they’re equal, the string is clean. You might also have to cast isalpha because it expects a predicate taking a char, not an int.

    For some samples using this algorithm, see here. Note that due to the version of GCC on there, std::begin() and std::end() were replaced, and the != was changed to == due to the reversed logic of the function (you’d use it like do {} while (!ok(...));).

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

Sidebar

Related Questions

Hey im getting this error when trying to validate a string. Basically i want
Hey im trying to store a string from a selected item in a datagrid
Hey Im trying to extract certain information from a string. The String looks like
Hey I am trying to understand the following code snippet. public static void main(String[]
Hey there, I'm trying to validate a form with Zend_Validate and Zend_Form. My element:
Hey trying to make a fancy little app here in VB.NET framework 4. I've
Hey I'm trying to make a clear button for my polish calculator.. code give
Hey I am trying to remove a querystring from a friendly URL i.e I
Hey i'm trying to display a date/time from a timestamp field using: echo $date
Hey i'm trying to build an app in which the user can input some

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.