I want to consult on this issue:
The names of sections in my ini file are such <int>:
- Code: Select all
[1]
name=Паста "Di Bocca"
price=210
text=
weight=400 г.
footer=(спагетти с креветками, морским гребешком, кальмаром, осьминогом и мидиями, приготовленные в сливочном соусе со свежими томатами, перцем Чили, чесноком и розмарином)
category=Пасты и ризотто
image=1.jpg
print=1
otdel=0
[2]
name=Паста "Неро"
price=170
text=
weight=420 г.
footer=(спагетти с чернилами каракатицы, тушеные в сливочном соусе с креветками, с мидиями, кальмарами, осьминогами, томатами, чесноком и белым вином)
category=Пасты и ризотто
image=2.jpg
print=1
otdel=0
[8]
name=Паста "Болоньезе"
price=135
text=
weight=360 г.
footer=(знаменитая паста с мясным соусом Болоньезе и сыром Пармезан)
category=Пасты и ризотто
image=8.jpg
print=1
otdel=0
//***
When I write a new section, I want to get a unique new value. The section name must be equal image=.
I chose this way:
- Code: Select all
std::vector<int> NameOfSection; //global
//***
std::unique_ptr<TMemIniFile> FileINI(new TMemIniFile(path, TEncoding::UTF8));
std::unique_ptr<TStringList> AlliniSection(new TStringList());
FileINI->ReadSections(AlliniSection.get());
NameOfSection.clear();
for (int i = 0; i < AlliniSection->Count; i++)
{
//check int 1... 2... 30... 135...
try
{
int check = StrToInt(AlliniSection->Strings[i]);
NameOfSection.push_back(check);
}
catch(...)
{
ShowMessage(L"No int in name of Section dibocca.ini");
return;
}
}
std::vector<int>::iterator maxnum = std::max_element(NameOfSection.begin(), NameOfSection.end());
int num = *maxnum + 1;
LabelNameImage->Caption = L"The name of the photo should be: " +
IntToStr(num) + L".jpg";
- Code: Select all
//Write a new section to a file
std::unique_ptr<TMemIniFile> FileINI(new TMemIniFile(path, TEncoding::UTF8));
std::vector<int>::iterator maxnum = std::max_element(NameOfSection.begin(), NameOfSection.end());
int num = *maxnum + 1;
//***
FileINI->WriteString(IntToStr(num), L"image", IntToStr(num)+L".jpg");
//***
FileINI->UpdateFile();
It seems everything is right and works. Is this the optimal solution?
P.S.
And the second question...
I have string with one number:
- Code: Select all
//Example
Итого: 250 грн.
//or
Итого: 1100 грн.
//or
Итого: 800 грн.
//***
What is the best way to read into a int variable number from this string?