How to extract the digit of a binary number in c++?

If i require the user to input a binary number, eg. "000010011", how can I extract each digit from the binary number?

Also, I want to check whether the input is valid. As the user should only input binary number with only "1" and "0", Otherwise, it will be considered as error. I only know that We can use for loop to operate it but I cannot think of the body part of the for loop . ( And we cannot use array to do it.)

Something along these lines...

1
2
3
4
5
6
char ch;
while ( cin.get(ch) ) {
  if ( ch == '\n' ) break;
  if ( ch == '0' ) ....
  if ( ch == '1' ) ....
}
salem c, have you ever noticed that many questions appear to be rather generic, and the poster has only 1 post count?

Curious, no?
@Niccolo,
It probably means that they only used their account for the one question. It can't be spammers (as I've seen it being suggested), because the website has a CAPTCHA check against that.
Just by statistics, most 1st-posters aren't spammers, so I don't think tinycymimi is one without more evidence.

That being said...
It can't be spammers (as I've seen it being suggested), because the website has a CAPTCHA check against that.
First, the captcha system employed by this site is outdated and can be cracked. Second, "spammer" does not necessarily mean "bot" -- it actually can be a human that they pay pitiful amounts of money to spam sites.
Ah, I thought CAPTCHAs were foolproof. Or, nearly so. And, I am sure there are probably places that pay people to spam sites, but what exactly would that accomplish?
if its another of those, its a convoluted advertising scheme.
its moronic, but it goes like this:
1) post a vague question
2) edit post with spam links and broken english gibberish //bypasses the check on spam if the site does not check edits but does check initial post.
3) hope people are stupid enough to click links like this to get paid.

a few places pay people to do the stupidest things. It must pay more than the labor costs, but they have people that just exploit popular games to get currency to trade off to others for real money.
Last edited on
¿so OP was using several resources to obtain the answer?
quite rude to derail the thread after just a couple hours.
Or, it's the "copy paste from SO/SE or reddit" spam tactic. Hard to tell which without seeing the exact stack exchange post.

My advice would be to just stop bumping this thread, and if OP responds back, great. If the OP is edited, then remove the post.
Hey, I am not spammer ... I am just new to programming and c++. I am a new user ...how can i have many posts?
I have posted the same question in other forum to get more answers. However, i have posted in the wrong forum so i deleted it. Is there any matter if i post the question to another forum? Or i only can use this forum to ask question?
I did not post any link and how can i be paid by other people????
It's ok, don't worry, they're just extra suspicious because this is not a secure website.

I think this would belong in the Beginners forum, not the General Programming one. But if you're not sure, read the admin posts up at the top to get an idea of what belongs in which forum.
tingcymimi, for the future, if you do post on multiple forums, it is good etiquette to reference the other thread. As agent max said, don't worry about the rabbit hole we went down talking about potential spam. We are just "paranoid" because we do get a lot of spam. Glad to see you're not a spammer.

Feel free to clarify your question if salem c didn't answer it.
Topic archived. No new replies allowed.