container the container ...

Good day all,
I must solve a problem and need your help.
The problem is that i whant a container of containers in string
"today;is;a;good,day;and;i;must,write;some;words" is for example a string.
I whant the a1 container for example of stings...
vector<strings> a1;
In a1 will insert the "today;is;a;good" and "day;and;i;must" and "write;some;words" strings(delimeter ","). Until now all are ok with a construct function or something else most convenient, i dont know what.
But when those strings constucting and import in a1, the a1 container must construct a2 container(delimeter ";") that holds (3) containers who have the sytem of n strings.
"today" "is" "a" "good"
"day" "and" "i" "must"
"write" "some" "words"
but how i make this?
thanks for all
best regards
Last edited on
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).
Last edited on
Thank's a lot.
Jim
Topic archived. No new replies allowed.