c++当stoi与sprintf共存时无法编译通过

问题遇到的现象和发生背景

stoi与sprintf共存时无法编译通过

问题相关代码,请勿粘贴截图
#include<string>
#include<algorithm>
#include<vector>
#include<sstream>
using namespace std;
int main()
{
    string s = "123";
    int a = std::stoi(s);
    int c = 2;
    char s2[2];
    sprintf(s2,"%d", c);
    cout << a;
}


运行结果及报错内容

img

我的解答思路和尝试过的方法
我想要达到的结果

求告知如何解决

sprintf第一个参数要求的是char* ,你给的是string,不兼容
改成
char buffer[20];
sprintf(buffer,"%d"...)

缺个#include <iostream>