0

我遇到一个问题,这是我的代码,

          _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.

所以任何机构都可以帮助我吗?

4

2 回答 2

1

未经测试,但应该可以正常工作:

const _wchar_t pBuffer[16] = {0};
wsprintf(pBuffer, L"%u", bstrTrans2)
_bstr_t bstrTrans3(pBuffer);
wsprintf(buf,L"insert into inven(ID) values(%s)",(wchar_t *)bstrTrans3 );
于 2013-03-01T09:06:03.003 回答
1

为什么不简单 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) 
于 2013-03-01T09:17:59.360 回答