我有以下代码,我正在尝试将整数更改为wstring,然后将其传递给文本文件。但问题是到达_itow_s(vec,img_stamp,10);行将其更改为负数。
任何人都知道是什么问题吗?

wchar_t img_stamp[64];
   while(c<_timeStamp.size()){
        vec=_timeStamp.at(c);
        _itow_s(vec, img_stamp, 10);
        _data +=std::wstring(img_stamp);
        _data +=std::wstring(L"\r\n");
        c++;
    }


    HANDLE hFile;
    DWORD wmWritten;
    hFile = CreateFile( "D:\\test\\testing.txt" ,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
    if(hFile!=NULL){

        DWORD len=sizeof(_data);
        WriteFile(hFile, _data.c_str(), _data.size() * 2, &wmWritten, NULL);
    }
    CloseHandle(hFile);

最佳答案

为什么不使用wstringstream

wstringstream ws;
for (...) { // some loop
  ws << myint << ", ";
}
//now, you can use ws.str() to extract a wstring from the stream

10-08 09:28