Read INF File in C++: Simple Guide
To read a .inf file in C++, you can use the standard file input stream ifstream. Below is a simple example code demonstrating how to read and output the contents of a .inf file.
#include <iostream>
#include <fstream>
#include <string>
int main() {
// 打开.inf文件
std::ifstream infFile("example.inf");
// 检查文件是否成功打开
if (!infFile.is_open()) {
std::cerr << "Error opening file." << std::endl;
return 1;
}
// 读取文件内容并输出到控制台
std::string line;
while (std::getline(infFile, line)) {
std::cout << line << std::endl;
}
// 关闭文件
infFile.close();
return 0;
}
In this example, we start by creating an ifstream object infFile to open a file named example.inf. Next, we use a while loop to read the file line by line and display the content on the console. Lastly, remember to close the file to release resources.
Please note that you need to replace example.inf with the actual file name of the .inf file you want to read.