Retrieving Variables from Text File

Hey experts i have a quick question. I have a text file config.txt which has:

"red = true"
"blue = false"
"children = 10"

I want to write a code that reads the values of these variables red, blue and children when executing the code.

I have something like this:

#include <iostream>
#include <string>
#include <fstream>

using namespace std;

int main ()
{
ifstream Configure;
Configure.open ("Config.txt");
if (!Configure){
cout << "Config.txt could not be accessed." << endl;
return 0;
}

char red;
char blue;
int children;


I want to read the read the values of red, blue and children in and use them when the program executes.



1
2
3
4
5
6
7
std::string line;

while(!Configure.eof())
{
getline(Configure, line); // you will keep getting each line, first red, then blue etc. do whatever you want to do with these.

}
Topic archived. No new replies allowed.