Simple trouble using character testing function

I'm getting this error.
 
|56|error: no matching function for call to 'isalpha(std::string&)'|


I understand that these character testing functions return ints, but I don't understand why I can't use them like how I want to use them. If the character is a letter then it should return true, and the if statement should execute the true statement returning the word variable.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>
#include <fstream>
#include <string>
#include <cctype>

void input();
void pigLatin(std::string);
std::string wordValidate(std::string);

int main()
{

    input();


    return 0;
}

//This function will take the input from the text file
//then send the input to the piglatin function.
void input ()
{
    std::string word;

    std::ifstream readFile;
    std::ofstream writeFile;

    readFile.open("ASSNG8-A.txt");
    writeFile.open("ASSNG8A-CONTENTS.txt");


    while (readFile >> word)
    {
        pigLatin(word);
    }

}

//This function will remove the first letter from a word and place it
//towards the end of the word. Then it will add the string "ay" to it.
void pigLatin(std::string pigWord)
{
    wordValidate(pigWord);
}


//This function verifies that the text is a letter.
//If the text is a letter, it returns the word.
//If the text is anything other than a letter,
//the function returns and error and keeps going.

std::string wordValidate(std::string palabra)
{
    std::string word;

    if (std::isalpha(word))
        return word;
    else if (isdigit(word))
        return "ERROR";
    else if (isalnum(word))
        return "ERROR";
}





int isalpha ( int c );
Checks whether c is an alphabetic letter.
A value different from zero (i.e., true) if indeed c is an alphabetic letter. Zero (i.e., false) otherwise.

http://www.cplusplus.com/reference/cctype/isalpha/

You need to loop through each character in the string and pass each character to isalpha().

Alternatively, you can use all_of() in the algorithm header.
http://www.cplusplus.com/reference/algorithm/all_of/
 
bool all_alpha{ all_of( palabra.begin( ), palabra.end( ), isalpha ) };
Last edited on
Topic archived. No new replies allowed.