从个位开始计数,然后是十位,以此类推

Count bits starting from the ones, then tens and so on

本文关键字:十位 以此类推 然后 开始      更新时间:2023-10-16

用c++编程

我正试图以字符串的形式从二进制代码中只打印出指定的数字。用户可以指定某个数字位置,并且必须打印该位置上的数字。

。字符串c = "11011001",用户想要第一个位置。输出必须为0。

计数索引从0开始,从"个位"开始,这意味着请求的第一个位置是"十位"位置上的数字。

我不知道如何从一列开始计数。我试过c.at(),但它从最左边的数字开始,向右计数。

你可以这样做:

#include <iostream>
#include <string>
int main ()
{
  std::string str ("11011001");
  int postion = 1;
  std::cout << str[str.length()-position];
}