读取存储在向量(行)中的.ini部分 [英] Read .ini section stored in vector(line)
问题描述
我有这个:
I have this:
freopen("CONOUT$", "w", stdout);
std::string Filename = "test.dat";
std::ifstream input(Filename, std::ios::binary | ios::in); // Open the file
std::string line; // Temp variable
std::vector<std::string> lines; // Vector for holding all lines in the file
while (std::getline(input, line)) // Read lines as long as the file is
{
lines.push_back(encryptDecrypt(line));
}
CIniReader iniReader("test.dat");
char *myip = iniReader.ReadString("test", "1", "127.0.1.9");
for (auto s : lines) // For each line in vector
{
cout << s; // Print it
cout << endl; // new line
}
test.dat是XOR-ed,我可以写得好,能够逐行读取,但我想要的是访问该数据的某些部分,存储ini样式课程:
test.dat is XOR-ed, and i can decript it ok, being able to read line by line, but what i want is to access certain sections of that data, stored ini style of course:
[test]
1 =
2 =
3 =
[test2]
1 =
2 =
3 =
我是一个乞丐,我不知道如何做到这一点......请帮忙吗?
I am a begginer, and i have no idea on how to do this... help please?
推荐答案
, w ,stdout);
std :: string Filename = test.dat ;
std :: ifstream输入(Filename,std :: ios :: binary | 中的ios :: ; // 打开文件
std :: string line; // 临时变量
std :: vector< std :: string>线; // 用于保存文件中所有行的向量
while (std :: getline(input,line)) // 只要读取行文件是
{
lines.push_back(encryptDecrypt(line));
}
CIniReader iniReader( test.dat< /跨度>);
char * myip = iniReader.ReadString( test, 1, 127.0.1.9);
for ( auto s:lines) // 对于向量中的每一行
{
cout<< S; // 打印
cout<< ENDL; // 新行
}
", "w", stdout); std::string Filename = "test.dat"; std::ifstream input(Filename, std::ios::binary | ios::in); // Open the file std::string line; // Temp variable std::vector<std::string> lines; // Vector for holding all lines in the file while (std::getline(input, line)) // Read lines as long as the file is { lines.push_back(encryptDecrypt(line)); } CIniReader iniReader("test.dat"); char *myip = iniReader.ReadString("test", "1", "127.0.1.9"); for (auto s : lines) // For each line in vector { cout << s; // Print it cout << endl; // new line }
test.dat是XOR-ed,我可以写得好,能够逐行读取,但我想要的是访问该数据的某些部分,存储ini样式课程:
test.dat is XOR-ed, and i can decript it ok, being able to read line by line, but what i want is to access certain sections of that data, stored ini style of course:
[test]
1 =
2 =
3 =
[test2]
1 =
2 =
3 =
我是一个乞丐,我不知道如何做到这一点......请帮忙吗?
I am a begginer, and i have no idea on how to do this... help please?
首先关于Windows API(GetPrivateProfile-s和WritePrivateProfile-s函数),我个人不建议任何人使用它们。这些是旧的,已弃用的和有缺陷的功能,仅仅因为与16位基于Windows的应用程序的兼容性而存在(阅读这些功能注意......)。
现在关于你的要求,有很多库能够处理INI文件的内容,你只需要搜索它们。
例如你是否尝试过以下方法:
https://github.com/brofield/simpleini [ ^ ]
但是我不确定是否有任何提供加密或解密的INI库,所以选择之后你需要创建一个包装函数的库,它会在将整个内容传递给所选的INI库之前解密整个内容,并加密从所选INI库提供的整个内容。
实际上我有一个可以加密/解密和操作的INI库最近的INI文件:
https://github.com/MarioZ/MadMilkman.Ini [ ^ ]
但它是一个.NET库所以我担心它需要套件你的需求,除非你使用C ++ / CLI。
First regarding the Windows API (GetPrivateProfile-s and WritePrivateProfile-s functions), I personally wouldn't recommend anyone to use them. These are old, deprecated and buggy functions that exist today purely because of compatibility with 16-bit Windows-based applications (read these functions "Note" ...).
Now regarding your requirements, there are quite a few libraries capable of processing INI file's content, you just need to search for them.
For example have you tried the following:
https://github.com/brofield/simpleini[^]
But I'm not sure if there is any INI library that provides encryption or decryption, so after you choose the library you would need to make a sort of a wrapper functions that would decrypt the whole content before passing it to the chosen INI library and encrypt the whole content provided from the chosen INI library.
Actually I have an INI library that can encrypt/decrypt and manipulate with INI files:
https://github.com/MarioZ/MadMilkman.Ini[^]
But it is a .NET library so I'm afraid it want suite your needs, unless you are using C++/CLI.
我宁愿使用Windows API
(例如,参见GetPrivateProfileInt function [ ^ ]与手工工具解析相反,用于检索INI
文件的条目。
I would rather useWindows API
(see, for instance, "GetPrivateProfileInt function"[^] as opposed to hand craft parsing for retrieving entries of aINI
file.
这篇关于读取存储在向量(行)中的.ini部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!