gpt4 book ai didi

c++ - 错误 : no matching function for call to 'isupper(std::string&)' |

转载 作者:行者123 更新时间:2023-11-28 06:26:05 30 4
gpt4 key购买 nike

谁能向我解释他们将如何找出字符串单词的大写和小写字母?我需要知道单词是说“fish”、“Fish”、“FISH”还是“fISH”。到目前为止,这是我的代码:

#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 语句。

关于c++ - 错误 : no matching function for call to 'isupper(std::string&)' |,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28511048/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com