You haven't shown the type of a. Is it a std::string or a char array?
In any case, you need to know the length of a;
1 2 3 4 5 6 7 8 9 10 11 12 13 14
unsigned len;
len = strlen(a); // if char array
len = a.size(); // if string
// Loop through the word
for (unsigned i=0; i<len i++)
{ if (a[i] == 'a')
cout << "10101 ";
if (a[i] == ''c')
cout << "01010 ";
if (a[i] == 'r')
cout << "01111 ";
}
cout << endl;
Of course you're going to need an if statement for every possible letter you want to encode. A table would work better.