Re: How to read Unicode(Big-Endian) text file(s) in Non-MFC
- From: "meme" <meme@xxxxxxxxxx>
- Date: Thu, 21 Feb 2008 17:31:19 +0530
"Giovanni Dicanio" <giovanni.dicanio@xxxxxxxxxxx> wrote in message
news:uXRZw9FdIHA.4172@xxxxxxxxxxxxxxxxxxxxxxx
"meme" <meme@xxxxxxxxxx> ha scritto nel messaggio
news:ePDCCR8cIHA.3400@xxxxxxxxxxxxxxxxxxxxxxx
Well...can I make a request here? Can you (or anyone else) might probably
point me to some good online resource about them?..... then perhaps.... I
might write proper C++ rather than C disguised as C++, some day...
:)..... (BTW thanks again for a good advise )
Google is your friend here.
You may find several tutorial and documentations.
And if you use Google on these newsgroups (or the MFC newsgroup) you may
also find some STL books suggestions.
However, about std::vector, the *basics* are:
1. You can create a vector containing BYTEs like this:
// Vector of BYTEs
std::vector< BYTE > data;
(As you understand, if you want to store type MyType in a vector, just use
'std::vector< MyType > data;').
To use vector, you have to #include <vector> header (you can #include it
in precompiled header like StdAfx.h, because the <vector> header won't
change :) during your development process).
2. To add items to vector, you can use push_back() method:
data.push_back( aByte );
data.push_back( anotherByte );
...
Vector size dynamically grows.
3. To get element count, you can use size() method:
size_t howManyElements = data.size();
4. Method clear() clears the vector:
data.clear(); // empty vector
5. You can access vector items using operator[] or method at().
The difference is that method at() does a bounds-checking on index. If
index is out of range, a std::out_of_range exception is thrown.
Instead, operator[] is like standard raw C operator[], and does no
bounds-checking.
So, using at() is more secure, but more slow; using operator[] is less
secure, but more fast.
// For each vector item:
for ( size_t i = 0; i < data.size(); i++ )
... access data[i] or data.at(i)
6. If you want to create a non-empty vector, you can specify start size
in constructor:
std::vector< BYTE > data(1000); // starts with 1000 items
and if you want to change vector size, you can use resize() method.
There is a lot more, like using iterators (a very powerful STL concept,
which allows you to write code that is in most part independent from the
underlying container), and other vector methdos.
The list of points 1-6 presented here are just the very basics, to start
using std::vector.
As a web reference, you may also look here:
http://www.cplusplus.com/reference/stl/vector/
HTH,
Giovanni
Thousand thanks .... for bringing on ( is this a valid English!!) the STL
..... I'm presently reading ( the link you and another very good link "Ben
Voigt" gave) and writting small codes to understand the class templates.....
and wow!.... it's not that hard and they are just doing fine so far..... Now
have to look on Iterators....algorithms....
.
- References:
- How to read Unicode(Big-Endian) text file(s) in Non-MFC
- From: meme
- Re: How to read Unicode(Big-Endian) text file(s) in Non-MFC
- From: Giovanni Dicanio
- Re: How to read Unicode(Big-Endian) text file(s) in Non-MFC
- From: meme
- Re: How to read Unicode(Big-Endian) text file(s) in Non-MFC
- From: Giovanni Dicanio
- Re: How to read Unicode(Big-Endian) text file(s) in Non-MFC
- From: meme
- Re: How to read Unicode(Big-Endian) text file(s) in Non-MFC
- From: Giovanni Dicanio
- Re: How to read Unicode(Big-Endian) text file(s) in Non-MFC
- From: meme
- Re: How to read Unicode(Big-Endian) text file(s) in Non-MFC
- From: Giovanni Dicanio
- How to read Unicode(Big-Endian) text file(s) in Non-MFC
- Prev by Date: Solved
- Next by Date: Re: malloc() size limit
- Previous by thread: Re: How to read Unicode(Big-Endian) text file(s) in Non-MFC
- Next by thread: Re: How to read Unicode(Big-Endian) text file(s) in Non-MFC
- Index(es):
Relevant Pages
|