繁体   English   中英

错误:没有匹配函数可调用'isupper(std :: string&)'|

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

谁能向我解释一下如何找到字符串单词的大写和小写字母? 我需要知道单词是说“鱼”,“鱼”,“鱼”还是“鱼”。 到目前为止,这是我的代码:

#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);
                }
            }
        }
    }
}

我曾尝试通过if语句和isupper / islower来弄清楚大写字母,但是很快我发现那是行不通的。 谢谢你的帮助。

isupper / islower函数采用单个字符。 您应该能够遍历字符串中的字符并检查大小写,如下所示:

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;
}

当然,在每种情况下,您都可以将cout语句替换为要执行的操作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM