当我试图运行这段代码时,我遇到了一些我无法查明原因的故障。前两个“cout”行显示数字 7 和 3,但是,最后一个“cout”行通常显示 50-60 之间的数字(在我运行它的那一刻,我得到 55 和 51,这似乎以某种方式关联位与我试图阅读的数字)。据我从谷歌搜索和手头的书籍中可以看出,这应该是有效的,但显然我缺少一些东西。感谢您的时间。
#include <iostream>
#include <string>
using namespace std;
int main()
{
string text = "73";
int one=0, two=0;
cout << text.at(0) << endl;
cout << text.at(1) << endl;
one = text.at(0);
two = text.at(1);
cout << one << endl << two << endl;
return 0;
}