0

I am a c++ beginner and I have a (probably simple) question. So far i have defined several variables:

double Start = 0;
double End = 1;
int Steps = 100; 

I want to change these values to a value that I have stated in a text file "paramaters.txt":

x_start = 0
x_end = 10
num_steps = 100

So my c++ needs to read the file and change the double End from 1 to 10. Reading the file can be done with this function:

std::ifstream file("parameters.txt")

I want to define a variable of type std::string, called label. Then i want to read the ’label’ from the file. Using a group of ’if (label == ”value”)’ statements to determine if I'm dealing with the start, end of the number of steps. Within the if-statement, the value of 10 would stand for the end for example.

I hope that someone can help me.

Regards,

asdfgqwer
  • 1
  • 1

1 Answers1

0

It seems you want to read a file for some values. You can do that by reading file line by line and then parsing each line.

For e.g in your case you would separate the line into two words with demiliter as "=".

But often the best way to read file for some values is to use some libraries. Like you can use boost::program options.

ravi
  • 10,994
  • 1
  • 18
  • 36