in the following code how would i set a txt file up to where i can have say name = whatever in it and the program will find it and set it to the corresponding global value.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <fstream>
#include <iostream>
#include <string>
usingnamespace std;
string name, sex;
int age;
int main()
{
ifstream inout("Example.txt");
inout >> name;
inout >> sex;
inout >> age;
cout << name << " "<<sex <<" "<< age << endl;
system("pause");
}
You should use getline function, it reads a whole line at a time so if you have in your .txt file something like "name = charles" you'll have to extract the name alone from the string, same thing with other lines.
Edit: Isn't this question suppose to be under "General C++" tab ?