Итак, у меня есть рабочая программа, которая успешно находит и отображает все символы в текстовом файле. Теперь я хочу читать целые слова вместо символов, а затем хочу хранить каждое слово в массиве, но я понятия не имею, как читать целые слова.Чтение слов и их хранение в массив
Мой текущий код для символов
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream infile("input.txt");
if (!infile)
{
cout << "ERROR: ";
cout << "Can't open input file\n";
}
infile >> noskipws;
while (!infile.eof())
{
char ch;
infile >> ch;
// Useful to check that the read isn't the end of file
// - this stops an extra character being output at the end of the loop
if (!infile.eof())
{
cout << ch << endl;
}
}
system("pause");
}
Вместо '>>' в 'char' вы можете' >> 'в' std :: string' – CoryKramer
Пожалуйста, прочитайте ссылку об этом утверждении: ['while (! Infile.eof())'] (http : //stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-considered-wrong) –