How to read all keys from a section of a . ini file? C++

Asked

Viewed 139 times

0

Can anyone help me with this question? I wanted to read all the keys of a section in a file ". ini" and use them as string.

Ex:

[ITENS]
pedido1 = 3552
pedido2 = 2208
pedido3 = 2066
pedido4 = 5787
pedido5 = 2966
pedido6 = 8889

Return: String array[] = [pedicle1, pedicle2, pedicle3, pedicle4, pedicle5, pedicle6]

I already use Getprofilestringa from "windows. privateh" to get a value from a key, but had trouble getting the name of all keys.

1 answer

0


The same thing from previous answer but playing in a Std::vector:

std::vector<std::string> chaves;
for(const char *resultado = lista; strlen(resultado); resultado += strlen(resultado) + 1)
    chaves.push_back(std::string(resultado, (int)(strchr(resultado, '=') - resultado)));
  • I’m kind of beginner. I tried it like this. I have difficulties converting variables. In the language I used it was all sort of automatic string system = "requested 1 = 3552 0requested 2 = 2208 0requested 3 = 2066 0"; Std::vector<Std::string> keys; for(const char *result = system; strlen(result); result += strlen(result) + 1) keys.push_back(Std::string(result, (int)(result, '=') - result)));

  • This is an example, but in this example, use char*system = ...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.