为什么模数运算符给出了错误的答案?

vat*_*sal -5 c++ string io stringstream mod

#include<iostream>
#include<string>
#include<sstream>

using namespace std;

int main(){
    stringstream ss;
    ss << 32;
    string str = ss.str();
    cout << str << endl
         << str[0] << endl
         << str[1] <<endl
         << str[0]%10;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出是:

32
3
2
1

相反,最后一行应为3,因为3%10 = 3.

Ale*_*dar 5

因为你将它与ascii值进行比较,它是51(0是48),modding给你1.你应该减去'0'或48,以便从汽车获得实数.