Let's model the idea, first. I would hate do see this thrown together for a single use and discarded; bare with me.
I would begin by modeling your data as types. For example, let's say that today is a Word type (in your specific case, today
is a ____?).
1 2 3 4 5 6 7
|
class Word
{
string _value;
public:
Word( string value ) : _value( value ) {}
// other operations that a user may perform on a Word
};
| |
Note that if the Word will not provide any additional operations it could just be a typedef for a string.
Then, I would model a collection of Words. For example, let Sentence represent related Words.
1 2 3 4 5 6 7 8 9 10 11 12 13
|
class Sentence
{
vector<Word> _data;
public:
Sentence( string data ) {
// parse a "today;is;a;good" string, using getline specifying
// semicolon delimiters, and construct Word objects to store
// in _data
}
// other operations that a user perform on a Sentence, such as a
// to-string-representation method that inserts semicolons between
// each Word
};
| |
Then, model a collection of Sentences. For example, let Paragraph represent related Sentences.
1 2 3 4 5 6 7 8 9 10 11 12 13
|
class Paragraph
{
vector<Sentence> _data;
public:
Paragraph( string data ) {
// parse a "today;is;a;good,day;and;i;must,etc" string, using getline specifying
// comma delimiters, and construct Sentence objects to store
// in _data
}
// other operations that a user perform on a Paragraph, such as a
// to-string-representation method that inserts commas between
// each Sentence
};
| |
Model and test at each iteration of development for best results.
This way, the code will be much more maintainable. You could open an ifstream, read strings and construct a Paragraph objects, store the objects, manipulate the objects with additional operations if that ever becomes necessary, open an ofstream, and write the Paragraphs to another file using their to-string-representation methods.
As for the implementation details that you seem to be asking about; visit the Reference section and see the getline method, vector container, and fstream class(es).