#include <iostream>
#include <vector>
using namespace std;
void print(int c)
{
cout << "0x" << hex << c << " ";
}
int main (int argc, char * const argv[])
{
char a[8] = { 'a', 'b', 'c', '1', '2', '3', 'z', 'y' };
vector<char> v(&a[0], &a[8]);
for_each(v.begin(), v.end(), print);
return 0;
}
Output:
[Session started at 2010-03-10 21:02:22 +0200.]
0x61 0x62 0x63 0x31 0x32 0x33 0x7a 0x79
The Debugger has exited with status 0.
Or "Hello, World!":
#include <iostream>
#include <vector>
using namespace std;
void print(int c)
{
cout << "0x" << uppercase << hex << c << " ";
}
int main (int argc, char * const argv[]) {
char* str = "Hello, World!";
vector<char> v(&str[0], &str[strlen(str)]);
for_each(v.begin(), v.end(), print);
return 0;
}
[Session started at 2010-03-10 21:23:06 +0200.]
0x48 0x65 0x6C 0x6C 0x6F 0x2C 0x20 0x57 0x6F 0x72 0x6C 0x64 0x21
The Debugger has exited with status 0.
No comments:
Post a Comment