Re: Multiple substrings = Error
Pistolen08@gmail.com wrote:
I can not post the entire code, but here is some more.
string str = string();
string binString = string();
string flipString1 = string();
string flipString2 = string();
string flipString3 = string();
string flipString4 = string();
As suggested before, you can safely drop all those '= string()'
parts. Strings are correctly initialised without that.
string toReverse = string();
This doesn't seem relevant at all.
out << toEncrypt;
What's the content of 'toEncrypt'?
binString = out.str();
Add
assert(binString.size() >= 8);
here
flipString1 = binString.substr(0,2);
flipString2 = binString.substr(2,2);
flipString3 = binString.substr(4,2);
flipString4 = binString.substr(6,2);
binString = flipString4 + flipString3 + flipString2 + flipString1;
cout << "after flip " << binString << endl;
If you don't want to post your actual code, it's fine with us,
but you have to realize that we're not mind readers.
If I have to guess, the error is in your 'toEncrypt' output. It
most likely does not produce long enough a string. Check the length
of 'binString'.
As a freebee, here is what your fragment should look like:
out << toEncrypt;
string binString = out.str();
string flipString1 = binString.substr(0,2);
string flipString2 = binString.substr(2,2);
string flipString3 = binString.substr(4,2);
string flipString4 = binString.substr(6,2);
string binString = flipString4 + flipString3
+ flipString2 + flipString1;
cout << "after flip " << binString << endl;
As you hopefully see, there is *absolutely* no need to define those
variables before they are going to be given some value.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask