Loop a list of Getprivateprofilesection C++

Asked

Viewed 55 times

1

I have a question, I’m a beginner. I wanted to list all the key names of an ini file, but only the name of the keys and loop from the first item to the last.

char lista[255];
GetPrivateProfileSection("ITENS",lista,255, ".\\arquivo.ini");
ostringstream os;
os << listando;
   for(int a = 0; a < lista; a=a+1){
os << lista[a];
}

I want the keys requested 1, requested 2, requested 3...

Arquivo.ini

[ITENS]
pedido1 = 3552
pedido2 = 2208
pedido3 = 2066
pedido4 = 5787
pedido5 = 2966
pedido6 = 8889
  • Quick tip, in increment do a++ because it will be better than a=a+1

1 answer

1


You should receive in list, something like: "pedido1 = 3552\0pedido2 = 2208\0pedido3 = 2066\0\0" 1 2

for(const char *resultado=lista; strlen(resultado); resultado+=strlen(resultado)+1)
    os << std::string(resultado, (int)(strchr(resultado, '=') - resultado));
  • And to read the sections of . ini? Getprivateprofilestring reads a string value from the .ini. file And how to read an entire section as a list, in only the name?

Browser other questions tagged

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