#Getting the incorrect output when using the << operator

1 messages · Page 1 of 1 (latest)

iron whale
#

The output should be the same as the inputted binary string but I am getting a different decimal number. I'm not sure what's wrong any help would be much appreciated, been working on this for awhile and just can't figure it out.

potent pantherBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

iron whale
#
zedlength = zed.length(); 

for(int i = 0; i <= zedLength; i++){

    if(zed[i] == '1')

    zed |= 1 << i;

}

std:: cout << zed; // Prints 27757```
old fossil
#

What is seed?

iron whale
#

Shoiuld be zed

old fossil
#

There are other weird things, but the problem is probably that i goes to zed.length() and zed[zed.length()] is invalid.

iron whale
#

zed.length() is just the length of the string

old fossil
#

Yes

#

Which is an invalid index.

#

Or maybe not if it's a C string.

#

It's so difficult to tell without seeing any code.

#

It would be great if you can show the problem on coliru or godbolt or something.

potent pantherBOT
#

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.