illusiate
illusiate

Reputation: 15

error: no matching function for call to 'isupper(std::string&)'|

can anyone explain to me how they would go about finding out the capital and lower case letters of string word? i need to know whether word is say "fish", "Fish","FISH", or "fISH." This is my code so far:

#include <iostream>
#include <string>
#include <cctype>
#include <fstream>
#include <sstream>
#include <locale>

using namespace std;

void
usage(char *progname, string msg){
    cerr << "Error: " << msg << endl;
    cerr << "Usage is: " << progname << " [filename]" << endl;
    cerr << " specifying filename reads from that file; no filename reads standard input" << endl;
}
int capitalization(string word){
    for(int i = 0; i <= word.length(); i++){

    }

}
int main(int argc, char *argv[]){
    string adj;
    string file;
    string line;
    string articles[14] = {"a","A","an","aN","An","AN","the","The","tHe","thE","THe","tHE","ThE","THE"};
    ifstream rfile;
    cin >> adj;
    cin >> file;
    rfile.open(file.c_str());
    if(rfile.fail()){
        cerr << "Error while attempting to open the file." << endl;
        return 0;
    }
    string::size_type pos;
    string word;
    string words[1024];
    while(getline(rfile,line,'\n')){
        istringstream iss(line);
        for(int i = 0; i <= line.length(); i++){
            iss >> word;
            words[i] = word;
            for(int j = 0; j <= 14; j++){
                if(word == articles[j]){
                    string article = word;
                    iss >> word;
                    pos = line.find(article);
                    cout << pos << endl;
                    capitalization(word);
                }
            }
        }
    }
}

I tried figuring out the capitalization with if statements and isupper/islower earlier, but i found out quickly that that wasnt going to work. Thanks for your help.

Upvotes: 0

Views: 3052

Answers (1)

Chris Usher
Chris Usher

Reputation: 169

The isupper/islower functions take in a single character. You should be able to loop through the characters in your string and check the case like so:

for (int i = 0; i < word.length(); i++) {
    if (isupper(word[i])) cout << word[i] << " is an uppercase letter!" << endl;
    else if (islower(word[i])) cout << word[i] << " is a lowercase letter!" << endl;
    else cout << word[i] << " is not a letter!" << endl;
}

Of course, you would replace the cout statements with whatever you want to do in each of those cases.

Upvotes: 1

Related Questions