View Full Version : 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?
Thanks,
E Dawg
Jefferson
12-07-2014, 12:35
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.
Joe Ross
12-07-2014, 14:49
How much do you understand about file i/o in general?
SoftwareBug2.0
12-07-2014, 15:26
http://www.cplusplus.com/doc/tutorial/files/
How much do you understand about file i/o in general?
Not that much. I've never really worked with it before.
connor.worley
14-07-2014, 12:57
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
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.