INI files

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jazzhouse

    #1

    INI files

    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
  • osmium

    #2
    Re: INI files

    "Jazzhouse" writes:
    [color=blue]
    >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?[/color]

    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.


    Comment

    • Karthik Kumar

      #3
      Re: INI files

      Jazzhouse wrote:[color=blue]
      > 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[/color]

      Aliter:

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

      Eg:

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

      }

      --
      Karthik.
      http://akktech.blogspot.com .

      Comment

      • Snyke

        #4
        Re: INI files

        Jazzhouse wrote:[color=blue]
        > 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[/color]
        int value atoi(str.c_str( ));

        should do :)

        Comment

        • Stewart Gordon

          #5
          Re: INI files

          Jazzhouse wrote:
          [color=blue]
          > I was trying to learn how the INI files work in C++, I am new to it.[/color]
          <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.

          Comment

          Working...