openvinotoolkit/openvino

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

Open

#26.680 aberto em 19 de set. de 2024

Ver no GitHub
 (19 comments) (0 reactions) (1 assignee)C++ (3.229 forks)auto 404
good first issue

Métricas do repositório

Stars
 (10.286 stars)
Métricas de merge de PR
 (Mesclagem média 14d 3h) (305 fundiu PRs em 30d)

Description

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.

Guia do colaborador