本文整理汇总了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;
}
示例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;
}