openvinotoolkit/openvino

CacheManager: std::ofstream constructor error due to missing .c_str() call on std::wstring

Open

#26,680 建立於 2024年9月19日

在 GitHub 查看
 (19 留言) (0 反應) (1 負責人)C++ (3,229 fork)auto 404
good first issue

倉庫指標

Star
 (10,286 star)
PR 合併指標
 (平均合併 14天 3小時) (30 天內合併 305 個 PR)

描述

https://github.com/openvinotoolkit/openvino/blob/bdc01107d989310c6efa7dd61c7fa5743c971f1d/src/inference/src/cache_manager.hpp#L128

I encountered a compilation error while building the OpenVINO project, specifically in the cache_manager.hpp file. The error occurs when attempting to construct a std::ofstream object with a std::wstring argument without first calling .c_str().

Error Message:

src/inference/src/cache_manager.hpp:129:91: error: no matching function for call to ‘std::basic_ofstream<wchar_t>::basic_ofstream(std::wstring, std::_Ios_Openmode)’
  129 |         std::wofstream stream(getBlobFile(id), std::ios_base::binary | std::wofstream::out);

Proposed Fix:

To resolve the error, I suggest modifying the line to convert the std::wstring returned by getBlobFile(id) to a const char* using the .c_str() method before passing it to the std::ofstream constructor.

std::ofstream stream(getBlobFile(id).c_str(), std::ios_base::binary | std::ofstream::out);
...
auto blobFileName = getBlobFile(id).c_str();

Justification:

std::ofstream does not have an overload that accepts std::wstring directly. The .c_str() method is necessary to provide the correct type (const char*) expected by the constructor.

貢獻者指南