当发生xutility错误时,我该怎么办

时间:2019-04-16 16:07:28

标签: c++ string visual-studio-2019

我想制作一个可以计算某个数字的每个数字的程序。 该数字是从控制台输入的三个整数的倍数。我将数字转换为字符串以进行计数并使用了计数功能。

#include<iostream>
#include<algorithm>
#include<string>
#include<stdlib.h>
using namespace std;
int main() {
    int a;
    int b;
    int c;
    cin >> a;
    cin >> b;
    cin >> c;
    int multi = a * b * c;
    string str_multi = to_string(multi);
    for (int a = 0; a <= 9;a++) {
        char* tmp;
        _itoa_s(a, tmp,2, 10);
        cout << count(str_multi.begin(), str_multi.end(), tmp) << endl;
    }
}

然后我得到了错误代码C2446。 错误消息,“'==':未从'const_TY'转换为'int'” 此错误在xutility文件中。我认为问题是计数功能或 _iota_s函数,但我不知道该如何解决。

1 个答案:

答案 0 :(得分:0)

在这种情况下,std::count的最后一个参数需要为char(或可以转换为char),因此只需将循环更改为:

for (int a = '0'; a <= '9'; a++) {
   cout << count(str_multi.begin(), str_multi.end(), a) << endl;
}

Live demo

相关问题