本文整理汇总了C++中WordList::wordSort方法的典型用法代码示例。如果您正苦于以下问题:C++ WordList::wordSort方法的具体用法?C++ WordList::wordSort怎么用?C++ WordList::wordSort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WordList
的用法示例。
在下文中一共展示了WordList::wordSort方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}