1: /**
2: * @author a.w(ad)quirixi.com
3: * @date 2001-12-12
4: *
5: * This little example shows the usage of class ByteString.
6: * Class ByteString is a class that is derived from std::vector and
7: * makes it easy for a C++ programmer to deal with bytes. It can be used
8: * similar to std::string.
9: * I use normal characters here instead of bytes since it is easier to
10: * give them out.
11: */
12:
13:
14:
15: #include <iostream>
16: #include "byte_string.h"
17:
18:
19:
20: int main ( void )
21: {
22: ByteString woman;
23: ByteString man;
24: ByteString love;
25:
26: woman = "Antonia"; // overloaded opertator= ( char*)
27: cout << "1. woman is now \"" << woman << "\"" << endl;
28:
29: man = 'A'; // overloaded opertator= ( char )
30: man += static_cast<BYTE> (0x6E); // 'n' : overloaded opertor+=(template basic_type)
31: man.push_back(0x74); // 't' : ByteString is dervived form std::vector
32: man += static_cast<WORD> (28271); // "on" : overloaded opertor+=(template basic_type)
33: cout << "2. man is now \"" << man<< "\"" << endl;
34:
35: char * sz_love = " loVe";
36: love.copy( sz_love, 5 ); // copy(void * buffer, size_t bufsize)
37: love[3] = 'v'; // remember ByteString is dervived form std::vector
38: love.push_back('s'); // char 's' is interpreted as BYTE automatically !
39: love.push_back(0x20); // space: 0x20 is interpreted as BYTE automatically !
40: cout << "3. love is now \"" << love << "\"" << endl;
41:
42: ByteString result = man;
43: result += love + woman + (BYTE)0x020 + "!" + (BYTE)0x0a; // append ' !\n'
44: // why does this work :-)
45: // carefull you have to cast!
46: cout << "4. result is now: " << result;
47:
48: return 0;
49: }
50:
51: /*
52: OUTPUT:
53: -------
54: 1. woman is now "Antonia"
55: 2. man is now "Anton"
56: 3. love is now " loves "
57: 4. result is now: Anton loves Antonia !
58: */