openvino: CacheManager: std::ofstream constructor error due to missing .c_str() call on std::wstring
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.
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 17 (5 by maintainers)
Hi @max-my Could you please send this patch as PR to OpenVINO repo?
@praasz I unassigned you because it forbids contributors from .taking the issue.
Thank you for providing the two solutions. After careful review and testing, I’ve found that the first solution is well-suited for addressing the specific error we’re encountering. While experimenting with the second solution, I encountered the need for additional code modifications due to the incompatibility of
writer(stream);andreader(stream);withstd::wofstream. The first solution, however, presents a more straightforward and efficient approach to achieving our desired outcome.