I need to extract full sentences from a file and the save them in a set. I tried getline to get a full line and then removed the characters after the period. This method doesn't work too well if the other half of the sentence is on another line. How should i fix this?
Do u think this code could work for scanning the sentences. Im using get line to get a sentence from the beginning to the period. Im using another line of code to delete the "\n" that is gonna be in the middle of sentences that spill over to the next line. Thanks for any help.
close, but you're using "while not eof", so the resulting set will include one extra string.
you can use remove instead of remove_if
and to make it look really like C++, move the string declaration closer to where it is used and don't call close()
or, for scope purists, for(string sentence; getline(file, sentence, '.'); )
2. Why shouldn't close() be called?
It's not an error, just bad style: the only time you need to do that in C++ is when you care about the return value/exception or when you're reusing the fstream object. Otherwise, let the destructor do it.
PS: also, removing endlines will make the words of your sentence stick together