我注意到在Windows上,文件打开不区分大小写.
(例如,fstream("text.txt")无论打开的实际文件名存在的:Text.txt)
我如何才能使这个区分大小写呢?(除非文件名也匹配正确的情况,否则文件无法打开)
在Windows下,文件系统API通常不区分大小写,因此唯一的方法是自己检查文件名的大小写.例如,
bool open_stream_ci(const char* pszName, std::fstream& out)
{
WIN32_FIND_DATAA wfd;
HANDLE hFind = ::FindFirstFileA(pszName, &wfd);
if (hFind != INVALID_HANDLE_VALUE)
{
::FindClose(hFind);
if (!strcmp(wfd.cFileName, ::PathFindFileNameA(pszName)))
{
out.open(pszName);
return true;
}
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
790 次 |
| 最近记录: |