从文本文档中输入字符串作为参数
C++ Feeding strings from a text document as arguments
是否有办法直接从文本文档作为参数提供字符串?最好不要救他们?
我有一个killProcessByName方法,期待一个参数,所以我想知道是否有可能从我的文本文档中读取第一行,复制它然后将其作为参数发送?然后移动到下一行,执行相同的操作并重复该过程,直到文档中没有剩下的单词。
列表示例:
Apples.exe
Blueberries.exe
Watermelon.exe
Oranges.exe
...
我针对的方法
void killProcessByName(const char *filename)
{
HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, NULL);
PROCESSENTRY32 pEntry;
pEntry.dwSize = sizeof (pEntry);
BOOL hRes = Process32First(hSnapShot, &pEntry);
while (hRes)
{
if (strcasecmp(pEntry.szExeFile, filename) == 0)
{
HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, 0,
(DWORD) pEntry.th32ProcessID);
if (hProcess != NULL)
{
TerminateProcess(hProcess, 9);
CloseHandle(hProcess);
}
}
hRes = Process32Next(hSnapShot, &pEntry);
}
CloseHandle(hSnapShot);
}
#include <iostream> // std::cout, std::endl
#include <fstream> // std::ifstream
using namespace std;
int main()
{
// open your file
ifstream input_file("test.txt");
// create variables
string name;
// while there are entries
while(input_file >> name)
{
killProcessByName(name.c_str());
}
// close the file
input_file.close();
return 0;
}
相关文章:
- 如何使用Luacneneneba API正确读取字符串和表参数
- 如何使用字符串文字作为宏参数
- 如何将可变长度参数联接为字符串
- 如何使用字符串find_first_of缓冲区形式(size_t n 参数)
- 具有字符串化的可变参数宏的现代/通用方法
- C++ 构造函数参数:字符串、整数、整数、整数
- 当C 中的系统调用conconculables时,参数字符串中的字符损失
- 模板参数字符串与整数
- #define 参数字符串化,但宽字符串 L " instead of "
- std::getline 用于 ifstream,使用参数字符串或 char *
- 通过参数字符串化宏调用模板函数
- 可变参数字符串比较
- 为什么位集的构造函数有参数字符串::charT 零,字符串::charT one)
- c++中stdbind在带有参数(字符串)的函数中的用法
- 当使用字符变量作为参数(字符串转换为字符)时,Std::rename()文件将不起作用
- C/ c++预处理器中的宏参数字符串化为宽字符串字面值
- 如何比较Visual C++中的参数字符串
- C++错误:推断出参数'T'字符串与常量字符的冲突类型 *
- 传递参数字符串,其中包含空格和引号
- 函数参数字符串通过引用传递