Reference text file in C++

I know that it is possible to reference a text file in C++ so that you are able to change variables without having to rebuild every time you want to change a constant. Does anyone know how to do that, and if so could you tell me how?

E Dawg

Check out RAWCConstants.
It was developed by other FRC teams and we stole shamelessly. It’s been super useful.

Edit: it was pointed out to me that I was violating the license agreement. I’ve removed the link to our repo. I’m not sue the official source for the tool. I wasn’t part of our original implementation.

How much do you understand about file i/o in general?

Not that much. I’ve never really worked with it before.

A simple way to do this in C++

#include <fstream>
#include <string>
#include <map>


std::ifstream constants("constants.txt");

std::map<std::string, double> data;

std::string name;
double value;

while(constants >> name >> value)

data[name] = value;

and a sample constants file

test 1
asdf 2.0
pi 3.14
negative -12.34