[Dev-C++] (code correction) Help with vectors
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Michael C U. <mu...@cb...> - 2004-01-08 02:44:02
|
Oops.
You need to declare "it" as being of type iterator. So in the for
definition, you want:
for (iterator it = myvec.begin(); it != myvec.end(); ++it)
The iterator as assigned above is a pointer to the first element of the
vector.
Mike
On Wed, 7 Jan 2004, Michael C Urban wrote:
> You get the data from a vector the same way you get the data from an
> array. So you can either use the subscript operator:
>
> myvec[0] // 1st vector element
> myvec[1] // 2nd vector element, etc.
>
> Or you can use pointer arithmetic to iterate through the elements:
>
> for (it = myvec.begin(); it != myvec.end(); ++it)
> {
> cout << *it << endl;
> }
>
> Does that answer your question?
>
> Mike
>
> On Wed, 7 Jan 2004, Maya wrote:
>
> > Ok I have managed to store data in a std::vector<...> object, but how
> > can I get the data from it?
> >
> > Thanks folks!!
> >
> >
> > jme::error_t jme::Index::bagIt(){
> > // temporary stream
> > jme::gnu_io tmp_stream;
> >
> > // temporary account object
> > jme::Account tmp_acc;
> >
> > // set file name
> > tmp_stream.setFileName(fname);
> >
> > // if the file stream does not exist return return error value
> > if(tmp_stream.notExist()){ return jme::fe_no_not_exist; }
> >
> > //set file mode
> > tmp_stream.setMode(tmp_stream.read_bin);
> >
> > // open file for reading
> > tmp_stream.Read();
> >
> > // if the file is empty let the class know and return error value
> > if(tmp_stream.is_empty()){
> > bag_empty = false;
> > return jme::fe_empty;
> > }
> >
> > // get the stream size
> > std::streampos fsz = tmp_stream.getFileSize();
> > do{
> > // Read a record into the jme::Account object
> > tmp_stream >> tmp_acc;
> > // add record to the container
> > bag.push_back(tmp_acc);
> > // do this while the maximum number of bits in the file are not
> > // reached
> > }while(fsz != tmp_stream.getNextRead());
> >
> > // sort the container
> > std::make_heap(bag.begin(), bag.end());
> > std::sort_heap(bag.begin(), bag.end());
> >
> > // Return jme::error_t::good
> > return jme::good;
> > }
> >
> > --
> >
> > FYI
> > http://www.astro.umd.edu/~marshall/abbrev.html
> >
> > E-Mail Policy
> > http://www.vif.com/users/escalante/Email_Policy.html
> >
> > * You cannot exercise your power to a point of humiliation.
> > - Jean Chretien
> >
> > * The media's the most powerful entity on earth. They have the
> > power to make the innocent guilty and to make the guilty
> > innocent, and that's power.
> > - Malcom X
> > * "Innocent until proven guilty", no... not in Canada!!
> >
> >
> >
> >
> > -------------------------------------------------------
> > This SF.net email is sponsored by: Perforce Software.
> > Perforce is the Fast Software Configuration Management System offering
> > advanced branching capabilities and atomic changes on 50+ platforms.
> > Free Eval! http://www.perforce.com/perforce/loadprog.html
> > _______________________________________________
> > Dev-cpp-users mailing list
> > Dev...@li...
> > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> >
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Perforce Software.
> Perforce is the Fast Software Configuration Management System offering
> advanced branching capabilities and atomic changes on 50+ platforms.
> Free Eval! http://www.perforce.com/perforce/loadprog.html
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|