CacheManager: std::ofstream constructor error due to missing .c_str() call on std::wstring
#26.680 aperta il 19 set 2024
Metriche repository
- Star
- (10.286 star)
- Metriche merge PR
- (Merge medio 14g 3h) (305 PR mergiate in 30 g)
Descrizione
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.