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
jabbaaAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
tycordinalConnect With a Mentor Commented:
#include "stdafx.h"
#include <iostream>
#include <string.h>

using namespace std;

// assuming that file contents read into a string here
char contents[] = "config1=name1\n\rconfig2=name2\n\rconfig3=name3\n\r";

char seps[]   = "\n\r=";  // separators
char *token;


int main(int argc, char* argv[])
{
  cout << "contents to be parsed:" << endl;
  cout << contents << endl;

  cout << "Tokens:" << endl;
  /* Establish contents and get the first token: */
  token = strtok( contents, seps );
 
  while( token != NULL )
  {
    /* While there are tokens in "contents" */
    cout << token << endl;
    /* Get next token: */
    token = strtok( NULL, seps );
  }

  return 0;
 
}
0
 
Kyle AbrahamsSenior .Net DeveloperCommented:
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.  
0
 
bkrahmerCommented:
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
0
 
tycordinalCommented:
...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
0
All Courses

From novice to tech pro — start learning today.