BOOL WINAPI WriteFile(
_In_ HANDLE hFile,
_In_ LPCVOID lpBuffer,
_In_ DWORD nNumberOfBytesToWrite,
_Out_opt_ LPDWORD lpNumberOfBytesWritten,
_Inout_opt_ LPOVERLAPPED lpOverlapped
);
WriteFile采用const void *。如何将std :: string转换为const void *,以便将字符串的内容写入磁盘?
答案 0 :(得分:5)
您可以使用c_str()
从char *
获取std::string
,然后您可以直接将其作为第二个参数传递给WriteFile
。如果没有,那么只需将指针转换为LPCVOID
。
有关c_str()
的详细信息,请参阅:
std::string to char*
答案 1 :(得分:0)
如您所知,LPCVOID
只是CONST void*
的typedef。因此,您可以将const char*
传递给该函数。 std::string
为c_str()
提供了一个函数。不需要强制转换,因为它们都是const限定的。