Я хотел бы получить совет/помощь в отношении разделения абзаца из отдельного текстового файла на собственные строки. Код, который у меня есть до сих пор, просто подсчитывает общее количество слов в этом абзаце, но я хотел бы разбить его, чтобы каждая строка была 1 предложением, а затем подсчитала количество слов в этом предложении/строке, а затем поместила это в свой собственный массив, чтобы я может делать другие вещи с этим конкретным чувством/линией. Вот что у меня есть код мудрый:Разделение абзаца отдельного текстового файла на отдельные строки
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
std::ifstream inFile;
inFile.open("Rhymes.txt", std::ios::in);
if (inFile.is_open())
{
string word;
unsigned long wordCount = 0;
while (!inFile.eo())
{
inFile >> word;
if (word.length() > 0)
{
wordCount++;
}
}
cout << "The file had " << wordCount << " word(s) in it." << endl;
}
system("PAUSE");
return 0;
}
Отдельный текстовый файл называется «Rhymes.txt» и содержит:
Today you are You, that is truer than true. There is no one alive who is Youer than You.
The more that you read, the more things you will know. The more that you learn, the more places you'll go.
How did it get so late so soon? Its night before its afternoon.
Today was good. Today was fun. Tomorrow is another one.
And will you succeed? Yes indeed, yes indeed! Ninety-eight and three-quarters percent guaranteed!
Think left and think right and think low and think high. Oh, the things you can think up if only you try!
Unless someone like you cares a whole awful lot, nothing is going to get better. It's not.
I'm sorry to say so but, sadly it's true that bang-ups and hang-ups can happen to you.
Таким образом, первая линия будет его собственное предложение и когда код выполнен, он сказал бы:
The line has 19 words in it
Я немного смущен как тоже, как бы я это сделал. Я видел примеры раскалывания предложений в слова, но я не мог найти ничего, что я мог бы понять, что связано с тем, что я прошу.
Это "отдельный", а не "индивидуальный". –