Reading white spaces from a text file along with letters as string values

I'm trying to read from a text file such as "the apple does not fall far from the tree" where each letter has a random assigned string value such as a=01000, b=00010, and so on. Also the spaces have value 99999. The text file needs to be translated to these string values. I cant figure out how to convert the spaces to their string value and get the text file to read straight through properly including the spaces. I've created if statements for each character that should convert them to strings but it still won't run correctly. I think I'm not reading the text file right somehow. Any feedback appreciated.

Last edited on
If you show us the code someone probably will tell you what's wrong.
<< streams ignore whitespace, read using getline.
then assuming you have something like

string? tbl[256] = { ... } ; //where tbl['a'] = "01000", ['b'] = "00010", and so on hardcode the values here.

you can simply transform it with a loop
for(...)
output += " " + tbl[input[index]];

it will work on spaces same as anything else.
Use istream::get():
1
2
3
4
char ch;
while (cin.get(ch)) {
    cout << table[ch];
}
Topic archived. No new replies allowed.