Re: How to read Unicode(Big-Endian) text file(s) in Non-MFC

Tech-Archive recommends: Speed Up your PC by fixing your registry



"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....


.



Relevant Pages

  • Re: How to read Unicode(Big-Endian) text file(s) in Non-MFC
    ... Google is your friend here. ... You can access vector items using operatoror method at. ... The difference is that method atdoes a bounds-checking on index. ... So, using atis more secure, but more slow; ...
    (microsoft.public.vc.language)
  • Re: Unprotecting a VBA Project
    ... > I had a look on google for password crackers for free, ... "Alan" wrote in message ... > At least I can go back to working on the assumption that my work is> 'reasonably' secure. ...
    (microsoft.public.excel.programming)
  • Re: When I press delete, I mean DELETE!!
    ... Search in Google for "secure ... > information after purchasing something online, ...
    (microsoft.public.security)
  • Re: You Have to Try This on Google
    ... >> I foresee entanglements... ... Google's core business is information ... I am convinced that it's way more secure in their datacentre compared ... Google Wallet, anyone? ...
    (alt.internet.search-engines)
  • Re: Permutations
    ... > next_permutation functions of the STL. ... unsuccessful in finding what you want to know via google. ... what you want but they also have NPR on their links. ... My favorite alternative solution is to look at a book. ...
    (comp.lang.cpp)