In C++, I want to sequentially read word from a text file, and store each word into an array? After that, I will perform some operation on this array. But I do not know how to handle the first phase: sequentially reading word from a text file and store each word into an array.
I should skip those punctuations, which include “.”, “,”, “?”
In C++, I want to sequentially read word from a text file, and store
Share
This sounds like homework. If it is, please be forthright.
First of all, it’s almost always a bad idea in C++ to use a raw array — using a vector is a much better idea. As for your question about punctuation — that’s up to your customer, but my inclination is to separate on whitespace.
Anyway, here’s an easy way to do it that takes advantage of
operator>>(istream&, string&)separating on whitespace by default.