我正在尝试创建一个字典,将文件读入字符串向量并计算每个唯一单词出现的次数。这是我到目前为止所拥有的:
int main()
{
ifstream input1;
input1.open("Base_text.txt");
vector<string> base_file;
vector<int> base_count;
if (input1.fail())
{
cout<<"Input file 1 opening failed."<<endl;
exit(1);
}
make_dictionary(input1, base_file, base_count);
}
void make_dictionary(istream& file, vector<string>& words, vector<int>& count)
{
string word;
int i=0;
while (file>>word)
{
words.push_back(word);
cout<<words[i];
i++;
}
for (i=0; i<words.size(); i++)
{
if ((words[i+1]!=words[i]))
{
count.push_back(i);
}
}
问题 1:如何让向量包含空格并识别单个单词?问题2:任何想法如何继续第二部分(for循环)?