Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Does C++ got something like properties in java?

Posted on 2003-03-28
4
Medium Priority
?
177 Views
Last Modified: 2012-05-04
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
0
Comment
Question by:jabbaa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 8229416
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
 
LVL 2

Expert Comment

by:bkrahmer
ID: 8231705
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
 

Accepted Solution

by:
tycordinal earned 120 total points
ID: 8233854
#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
 

Expert Comment

by:tycordinal
ID: 8233859
...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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question