当我按原样运行该程序时,返回的文本没有任何空格。如何让它分别识别每个单词?
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);
}
}
}
电流输出:
Thisissomesimplebasetexttouseforcomparisonwithotherfiles.Youmayuseyourownifyousochoose;yourprogramshouldn'tactuallycare.Forgettinginterestingresults,longerpassagesoftextmaybeuseful.Intheory,afullnovelmightwork,althoughitwilllikelybesomewhatslow.
预期的输出应该在每个单词之间有空格。在此之后我需要能够按字母顺序对单词进行排序,所以我需要修复的不仅仅是输出。