cplusplus.com cplusplus.com
cplusplus.com   C++ : Forums : UNIX/Linux Programming : read ini file
  Search:
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forums
Forums
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Articles
Lounge
Jobs

-

question  read ini file

detorresrc
what can i do to read my program this ini file.

for example this is the content of my.ini:

a=1
b=2
| Last edited on
firedraco
Well, you could probably just do it this way:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <ostream>
#include <string>

int main(void) {
     ostream Stream;
     string buffer;
     Stream.open("file.ini"); //or whatever the path is to your .ini file
     if(!Stream.is_open()) {
          cerr << "Error, file was unable to be opened.";
          return 0;
     }
     while(!Stream.eof()) {
          getline(Stream, buffer);
          //do stuff with buffer...
     }
     Stream.close();
     return 0;
}
| Last edited on
detorresrc
thanks..
|

Registered users can reply in this forum.
Home page | Privacy policy
© cplusplus.com, 2000-2008 - All rights reserved - v2.2
Spotted an error? contact us