I read about iteration an it seems an iterator should do the trick. This is what I ended up with.
Code:
string compstr;
string::iterator it;
int index = offset;
..for ( it = str.begin() ; it < str.end(); ++it){
if (index%4 == 0){
.. compstr += (char)map.find(str.substr(index,4))->second;
}
index++;
}
return compstr;
Don't hesitate to comment if I've got it wrong in some way.
As I wrote in my last post, there's still popping up segmentation fault. It seems to be some issue in a file to string function I use. If I hard code the string directly in my code everything is fine and dandy. But if I use my file2string function I sometimes get segfault.