|
From: Maya <Esc...@ne...> - 2004-01-08 01:50:14
|
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!!
|
|
From: Michael C U. <mu...@cb...> - 2004-01-08 02:39:55
|
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
>
|
|
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
>
|
|
From: Maya <Esc...@ne...> - 2004-01-08 15:03:14
|
Yes, that was my solution too, but now I a faced with another problem.
When calling the function member
'const jme::Account& jme::Index::getData() const; ' I don't have the
means of knowing the number of elements in the vector, but I am sure
that HP must have anticipated this problem and add a method that will
return the number of elements in the array.
Mike, thank you so very much for your help!!
mu...@cb... wrote:
>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
>>
>>
>>
>
>
>-------------------------------------------------------
>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
>
>
--
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!!
|
|
From: Michael C U. <mu...@cb...> - 2004-01-08 19:02:20
|
Maya,
If if you are using the standard C++ vector class, then you should be able
to obtain its size by calling its size() method. So for example:
int vec_size = myVec.size();
But I might be missing what exactly your problem is. Are you trying to
access a private vector through a public interface method?
Mike
On Thu, 8 Jan 2004, Maya wrote:
> Yes, that was my solution too, but now I a faced with another problem.
> When calling the function member
> 'const jme::Account& jme::Index::getData() const; ' I don't have the
> means of knowing the number of elements in the vector, but I am sure
> that HP must have anticipated this problem and add a method that will
> return the number of elements in the array.
>
> Mike, thank you so very much for your help!!
>
> mu...@cb... wrote:
>
> >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
> >>
> >>
> >>
> >
> >
> >-------------------------------------------------------
> >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
> >
> >
>
> --
>
> 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
>
|