point next object in a file

Hello everybody!
I am here to ask you some help one more time.I have a file woch contains string.This string is "separated" in substrings which represent an object(each substring).I have a method to read those objects and another that does some operations on them.All I want is to find a way to show which object is going to be read next.
Ask anything you cant understand.
Thanks in advance.
I would put all the substrings into a vector or other std:: container, then just use an iterator to get the next one. (Just be careful of modifying the container, it will invalidate your iterators)
Yes,I have thought this kind of solution but I cant use vector,only array.If I can find a way to find its size it will be great.But substrings dont have a constant number of chars:s
Do you have some other ideas?
Use a dinamic array of strings
Hmm,I am not sure what do you mean.Can you give me a small example,please?
Of course a standard container is better than this, but without STL I would do something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <fstream>
#include <string>
unsigned int s = 1; // size of your array
string *array = new string[s];
void IncreaseArray( unsigned int amount = 1 )
{
     string *copy = new string[s];
     int n;
     for (n=0; n<s; n++)
          copy[n]=array[n];
     delete[] array;
     s += amount;
     array = new string[s];
     for ( n-- ; n>=0; n--)
          array[n]=copy[n];
     delete[] copy;
}

then call IncreaseArray each time you want to add elements to array
Last edited on
Ok,I ve got it.Thanks a lot bazzy
Topic archived. No new replies allowed.