我遇到一个问题,这是我的代码,
_bstr_t bstrTrans=L"2";
wsprintf(buf,L"insert into inven(ID) values(%s)",(wchar_t *)bstrTrans)//insert into database
//this can work fine, now we want to let bstrTrans add 1, likes this
int bstrTrans2 = atoi(bstrTrans) + 1;
wsprintf(buf,L"insert into inven(ID) values(%s)",(wchar_t *)bstrTrans2 )
// now ,it cannot work.
有人可以帮我吗?
最佳答案
为什么不简单地使用s-> d?
_bstr_t bstrTrans=L"2";
wsprintf(buf,L"insert into inven(ID) values(%s)",(wchar_t *)bstrTrans)
//insert into database
//this can work fine, now we want to let bstrTrans add 1, likes this
int bstrTrans2 = atoi(bstrTrans) + 1;
wsprintf(buf,L"insert into inven(ID) values(%d)",bstrTrans2 )
编辑:嗯,这项工作?
_bstr_t bstrTrans=L"2";
wsprintf(buf,L"insert into inven(ID) values(%s)",(wchar_t *)bstrTrans)
//insert into database
//this can work fine, now we want to let bstrTrans add 1, likes this
char t[30];
bstrTrans = itoa ( atoi (bstrTrans) + 1 , t,10);
wsprintf(buf,L"insert into inven(ID) values(%s)",(wchar_t *)bstrTrans)