W jaki sposób wczytać liczby oraz nazwy opcji, chcę zmodyfikować ten kod:
#include <iostream>
#include <fstream>
#include <string>
int main()
{
std::string option = "";
std::string value = "";
std::string line = "";
std::ifstream cfg("game.cfg");
int index = 0;
if (cfg.is_open())
{
while (getline(cfg, line) )
{
if(line[0] != '#' && line != "")
{
value = line;
option = line;
index = option.find('=');
value.erase(0, index+1);
option.erase(index, line.length()-1);
index = 0;
line = "";
std::cout<<option<<" = "<<value<<"\n";
option = "";
value = ""; //Chcę mieć liczby
}
}
cfg.close();
}
}
Przykładowy plik:
#GAME CLIENT CONFIGURATION FILE
#DO NOT CHANGE ANY CONTENTS OF THIS FILE
#########################################
#ONLY FOR PEOPLE WHO KNOW WHAT TO DO HERE
#########################################
#BEGIN
fullscreen=1 //nazwa_opcji=liczba
width=0
height=0
vsync=0
renderdistance=100
#END