Link to home
Start Free TrialLog in
Avatar of jabbaa
jabbaa

asked on

Does C++ got something like properties in java?

Hi there,

I would like to ask does C++ got some class or library like the properties in java. Which can read a test file's data using for configuration in the program.

e.g.
config.properties
config1=name1
config2=name2
config3=name3

Then the program read config.properties and can have some ways to access config1's value


Regards
Jabba
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

ifstream config1(name1); //create an input stream to file.
ifstream config2(name2);

then you can read in configs like you do a cin.

int x;
while (config1 >> x != EOF) //get values from file.  note: EOF may be differnetly defined depending on compiler.
  //do your code here.
     
name1 has data:
2 3 4 5 etc.

All of the >> rules apply, will read up to white space, etc.  
Avatar of bkrahmer
bkrahmer

I work on a large cross-platform project in C++.  We use an object that encapsulates an .ini file reader/writer.  On windows, you can use the GetPrivateProfileXXX functions to do this type of work.  

cheers,
brian
ASKER CERTIFIED SOLUTION
Avatar of tycordinal
tycordinal

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
...one thing to mention, #include "stdafx.h" is only for VC++, if your aren't, you don't need it.


the output of the program:


contents to be parsed:
config1=name1
config2=name2
config3=name3

Tokens:
config1
name1
config2
name2
config3
name3