Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Reference text file in C++ (http://www.chiefdelphi.com/forums/showthread.php?t=130024)

E Dawg 12-07-2014 11:15

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

Re: Reference text file in C++
 
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

Re: Reference text file in C++
 
How much do you understand about file i/o in general?

SoftwareBug2.0 12-07-2014 15:26

Re: Reference text file in C++
 
http://www.cplusplus.com/doc/tutorial/files/

E Dawg 14-07-2014 09:32

Re: Reference text file in C++
 
Quote:

Originally Posted by Joe Ross (Post 1392866)
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

Re: Reference text file in C++
 
A simple way to do this in C++

Code:

#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

Code:

test 1
asdf 2.0
pi 3.14
negative -12.34



All times are GMT -5. The time now is 02:42.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi