【发布时间】:2021-06-15 05:52:05
【问题描述】:
我正在使用 Arduino/C 进行转换器项目。在我的代码中的某个点,生成了一个由 0 和 1 组成的 String 序列,例如:
my_string = "01101";。我想在 for 循环中处理这些数据,如这个最小示例所示:
String x = "01011", y = "00011"; // These variables necessarily must have the same length
for(int i = 5; i > -1; i--) // Going from last index to first
{
bitsum = x[i].toInt() + y[i].toInt(); // Summing up each pair of bit, here is the problem
}
我的意思是:有没有办法将String 中的一个准确而具体的元素一个一个地转换为int?
提前致谢!
【问题讨论】:
-
Arduino 通常是用 C++ 编程的,你使用
String类意味着你也在这样做。 -
对不起。我不确定我是否理解你所说的关于字符串的内容。介意解释一下吗?
-
他只是在推断您不是在谈论 C,因为您的代码使用了 Arduino(即 C++)
String对象。 -
谢谢你们的澄清!
标签: c++ string arduino type-conversion integer