当前位置: 首页>>代码示例>>C++>>正文


C++ WordList::addWord方法代码示例

本文整理汇总了C++中WordList::addWord方法的典型用法代码示例。如果您正苦于以下问题:C++ WordList::addWord方法的具体用法?C++ WordList::addWord怎么用?C++ WordList::addWord使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WordList的用法示例。


在下文中一共展示了WordList::addWord方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main (int argc, char* argv[]) {
  if(argc == 1) {
    cout << "Please select a file." << endl;
  }
  else {
      //Open File
      ifstream fileInput  (argv[1]);
      
      if(!fileInput.is_open()) {
        cout << "Unable to open " << argv[1] << endl;
      }
      else {
        cout << argv[1] << " opened." << endl;
        string word;
        WordList wordList;
        while(fileInput >> word) {
          if( word[word.size()-1] == ',' ||
              word[word.size()-1] == '!' ||
              word[word.size()-1] == '.' ||
              word[word.size()-1] == ';' ||
              word[word.size()-1] == ':' ||
              word[word.size()-1] == '?' ||
              word[word.size()-1] == '-' ||
              word[word.size()-1] == '"' ||
              word[word.size()-1] == '+') 
          {
            word.erase(word.size()-1);
          }
          wordList.addWord(word);
          //cout << word << endl;
            
        }
        
        wordList.sortList();
        wordList.printList();

        // Close File
        fileInput.close();
      }
  }
  
  return 0;
}
开发者ID:quartarian,项目名称:CS3,代码行数:43,代码来源:main.cpp

示例2: main

int main(int argc,const char * argv[])
{

    // insert code here...

    //open file
    
    std::ifstream inputFile;
    inputFile.open(argv[1]);
    
    
    if(!inputFile.is_open())
    {
        cout << argv[1] << " was not open" << endl;
        return 1;
    }
    
    if (inputFile.is_open()) {
        
        cout << argv[1] << " is open!" << endl;
    }
    //declare the strings to use
    string  inputString;
    string buffer;
    
    //declare object needed
    WordList nameList;
    
    //get the stuff from the file
    getline(inputFile, inputString);
    //cout << "done reading in" << endl;
    
    //loop to check for the code being at the end of the file
    while (!inputFile.eof()) {

        //cout << "in the while loop " << end;
        //loops over the whole input string
        for(int i = 0; i < inputString.length(); ++i)
        {
            //checks for letters and characters
            for (int k = i; isalpha(inputString[k]) && inputString[k] != ','; ++k, ++i)
            {
                buffer += inputString[k];
            }
            
            //adds words
            //cout << " adding words " << endl;
            nameList.addWord(buffer);
            buffer.clear();
        }
        
        getline (inputFile, inputString);
    }
    
    //cout<<"out of while loop" << endl;
    
    //sorts the words in decending order
    buffer.clear();
    //cout << "sorting stuff " << endl;
    nameList.wordSort();
    //cout << "done sorting stuff " << endl;
    inputFile.close();
    //cout << "file closed " << endl;
    
    return 0;
}
开发者ID:alfred316,项目名称:KSU-CS3,代码行数:66,代码来源:wordCounter.cpp


注:本文中的WordList::addWord方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。