INI files

J

Jazzhouse

I was trying to learn how the INI files work in C++, I am new to it.

I have found a code at http://www.codeproject.com/cpp/cinifile.asp

I manage to read a value as STRING.

Now, I want to turn it into an integer but I cannot. If it was a CHAR I
would use atoi isnt it? But what shall I do now?

Ferhat
 
O

osmium

Jazzhouse said:
I was trying to learn how the INI files work in C++, I am new to it.

I have found a code at http://www.codeproject.com/cpp/cinifile.asp

I manage to read a value as STRING.

Now, I want to turn it into an integer but I cannot. If it was a CHAR I
would use atoi isnt it? But what shall I do now?

atoi() will do what you want. Look at the declaration more closely, it is
char*n - not simply char - which is another word for C style strings.
 
K

Karthik Kumar

Jazzhouse said:
I was trying to learn how the INI files work in C++, I am new to it.

I have found a code at http://www.codeproject.com/cpp/cinifile.asp

I manage to read a value as STRING.

Now, I want to turn it into an integer but I cannot. If it was a CHAR I
would use atoi isnt it? But what shall I do now?

Ferhat

Aliter:

Look into stringstreams in C++ . They are much more cleaner.

Eg:

int GetInt(const std::string & value) {
std::istringstream is(value);
int a;
is >> a;
return a;

}
 
S

Stewart Gordon

Jazzhouse said:
I was trying to learn how the INI files work in C++, I am new to it.
<snip>

Looks a little nicer than the Windows API for INI files. I wonder if
whoever wrote this:
- hadn't discovered the Windows API functions for this
- wanted a nicer, OO interface
- wanted a cross-platform solution

Though I would have made naming the file and loading it the same
operation, and probably put it in the constructor.

I developed a thing called Configur8, which is a file format similar to
INI but with the ability to include stuff. I got as far as mostly
coding it up (well, enough for my purposes at the mo) in C, C++ and F90.
But it's a read-only interface at the moment....

Stewart.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top