简体   繁体   English

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

[英]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. 我曾尝试通过if语句和isupper / islower来弄清楚大写字母,但是很快我发现那是行不通的。 Thanks for your help. 谢谢你的帮助。

The isupper/islower functions take in a single character. isupper / islower函数采用单个字符。 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. 当然,在每种情况下,您都可以将cout语句替换为要执行的操作。

暂无
暂无

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

相关问题 错误:没有匹配函数来调用...(std :: string&) - error: no matching function for call to…(std::string&) 错误:没有用于调用“getline(FILE*&amp;, std::string&amp;)”的匹配函数 - error: no matching function for call to 'getline(FILE*&, std::string&)' 字符串的排列-错误:没有匹配的函数来调用&#39;std :: set <char> :: insert(std :: string&)&#39; - Permutations of a string --error: no matching function for call to ‘std::set<char>::insert(std::string&)’ 为什么这个编译错误? - 没有匹配函数来调用&#39;std :: basic_ofstream <char> ::打开(的std :: string&)” - why this compiler error? - no matching function for call to 'std::basic_ofstream<char>::open(std::string&)' 使用 getline 给出错误:没有匹配的 function 调用 'getline(std::istream&amp;, const string&amp;)' - using getline gives error: no matching function for call to ‘getline(std::istream&, const string&)’ 错误:没有匹配的函数调用&#39;std::basic_ifstream<char> ::basic_ifstream(std::__cxx11::string&amp;)&#39; - error: no matching function for call to 'std::basic_ifstream<char>::basic_ifstream(std::__cxx11::string&)' “没有匹配函数来调用'async(std :: launch,<unresolved overloaded function type>,std :: string&)'” - “no matching function for call to ‘async(std::launch, <unresolved overloaded function type>, std::string&)’” 没有匹配的 function 调用 'std::vector::push_back(std::string&amp;)' - No matching function for call to ‘std::vector::push_back(std::string&)’ 为什么C ++中的getline()无法正常工作? (没有匹配函数可调用“ getline(std :: ofstream&,std :: string&)” - Why is getline() in C++ not working? (no matching function for call to 'getline(std::ofstream&, std::string&)' 没有匹配的 function 调用 'LiquidCrystal::write(String&amp;)' - no matching function for call to 'LiquidCrystal::write(String&)'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM