📄 testwordcount.cpp
字号:
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include "wordcount.h"
using namespace std;//::cout;
typedef vector<string>::size_type vec_sz;
bool output_already(const string& word, const vector<string>& output_words)
{
vec_sz size = output_words.size();
for(vec_sz i = 0; i < size; ++i)
{
if(word == output_words[i])
return true;
}
return false;
}
void main()
{
wordcount counter;
string word;
string qut="/#";
vector<string> words;
vector<string> output_words;
fstream file;
cout<<"input words:";
for ( ; ; )
if ( counter.readin() )
counter.count();
else
{
counter.count();
break;
}
file.open("data.txt",ios::in);
while( file >> word)
{
if (word!=qut)
words.push_back(word);
else
break;
}
const vec_sz words_size = words.size();
for(vec_sz i = 0; i < words_size; ++i)
{
if (output_already(words[i], output_words)) continue;
int count = 0;
for(vec_sz j = 0; j < words_size; ++j)
if(words[i] == words[j]) ++count;
cout << "There are/is " << count << " \"" << words[i] << "\" in your input." << endl;
output_words.push_back(words[i]);
}
file.close();
cout<<" total "<<counter.getcount()<<" words "<<endl;
system("pause");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -