从c++文本文件中读取黑名单
Reading blacklist from a text file in C++
我实际上需要我的驱动程序(逐行)读取一些将要被列入黑名单的程序。
_T("bannedfile.exe")是我实际需要放置黑名单程序的地方。
如何使_tcscmp逐行读取文本文件?
(它将加载驱动程序的主机程序与列入黑名单的程序进行比较)
BOOL ProcessBlackList() {
TCHAR modulename[MAX_PATH];
GetModuleFileName(NULL, modulename, MAX_PATH);
PathStripPath(modulename);
if (_tcscmp(modulename, _T("bannedfile.exe")) != 1) {
return 0;
}
else {
return 0x2;
}
}
不能那样做。
您应该能够使用use getline来逐行读取文件,然后将这些行传递给_tcscmp。应该是这样的:
wchar_t const name[] = L"bannedfile.exe";
std::wifstream file(name);
std::wstring line;
while (std::getline(file, line)
{
if (_tcscmp(modulename, line.c_str()) == 0) {
return TRUE; //module is in list
}
}
return FALSE; // module is not in list
目前缺少VS的副本来测试。
如果你遇到unicode解析问题,因为文件的编码不完全是默认的期望,给这个读:std::wifstream::getline对我的wchar_t数组做了什么?在getline返回
相关文章:
- 理解boost::asio-async_read在无需读取内容时的行为
- 使用新行和不使用新行读取文件
- 读取文件并输入到矢量中
- 用c++从输入文件中读取另一行
- 读取文件的最后一行并输入到链接列表时出错
- 在进程中对同一管道进行读取和写入时C++管道出现问题
- 无法找到/读取配置文件.conf-FileIOException
- 如何使用Luacneneneba API正确读取字符串和表参数
- C++将文本文件中的数据读取到结构数组中
- 正在将csv文件读取为双精度矢量
- 为什么 sscanf 无法从一个字符串中读取uint64_t和字符?
- 为什么在读取文件大小时文件IO速度会发生变化
- 正在读取二进制文件(is_open)
- 如何在c++中从文本文件中逐行读取整数
- SSH通过/sbin/SSH无法读取RSA密钥文件(从控制台运行)
- 独立读取-修改-写入顺序
- 从文本文件中读取时钟时间和事件时间并进行处理
- 如何从文本文件中读取值和数组
- 为什么文件名被设置为一个点,而不是在读取矢量中的文件名时
- 从c++文本文件中读取黑名单