I am using the windows API in C++ and I want to get the content of a specific txt file. I contemplate using the ReadFile
function but I don' t know what I should use in place of HANDLE
or, in other words, how I should pass as parameter the name of the txt file. What is the best way generally to get the content of a txt file using windows API.
问问题
208 次
3 回答
2
使用CreateFile()
, 提供GENERIC_READ
参数dwDesiredAccess
和参数,以获得传递给OPEN_EXISTING
的a 。dwCreationDisposition
HANDLE
ReadFile()
或者,更简单,只需使用std::ifstream
:
#include <fstream>
#include <vector>
#include <string>
...
std::vector<std::sting> lines;
std::ifstream in("input.txt");
if (in.is_open())
{
std::string line;
while (std::getline(in, line)) lines.push_back(line);
}
于 2012-07-03T13:52:15.743 回答
2
首先,您必须调用CreateFile
(“创建或打开文件或 I/O 设备”)。它返回一个句柄,您随后将其传递给ReadFile
.
完成后,不要忘记调用CloseHandle。
于 2012-07-03T13:52:06.603 回答
0
您可以使用CreateFile函数创建 HANDLE 。
于 2012-07-03T13:52:23.273 回答