0

我正在为翻译程序编写程序。现在,我正在编写一个单词类,如下所示,我在编写返回句子中所有带有撇号的单词的方法时遇到了麻烦。在 bool Words::isApostophePresent(){ 之后我应该写什么

如果(.....)

 Words::Words() {}

string Words::getWord(){
      return word;
}

void Words::setWord(string w){
     word=w;
}

int Words::getNumCharacters(){
   return word.length();
}

vector<char> Words::getCharacters(){
      int numChars=word.length();
      for (int i=0;i<numChars;i++){
           characters.push_back(word[i]);
      }
      return characters;
}

bool Words::isFirstCharacterUppercase(){

   if(isupper(word[0])){
      firstCharacterUppercase=1;
   }
   else {
      firstCharacterUppercase=0;
   }
   return firstCharacterUppercase;
}

bool Words::isApostophePresent(){

   if()





}
Words::~Words(){}
4

1 回答 1

1
#include <string>
#include <iostream>

const std::string STR1 = "Hello'World";
const std::string STR2 = "Hello World";

bool hasApostrophe(const std::string& s){ 
  return s.find("'", 0, 1) != std::string::npos; 
}

int main(int, char**){

    std::cout << STR1 << " has apostrophe = " << hasApostrophe(STR1) << '\n';
    std::cout << STR2 << " has apostrophe = " << hasApostrophe(STR2) << '\n';
    return 0;
}
于 2020-04-11T12:10:03.787 回答