Thread: Playing with .ini files.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    You are indexing into a string called foo, but you create it with a default constructor, which means that all indices are invalid (the string storage doesn't/may not exist). May-be you should append characters to the empty string.

    There are also string functions that are able to find '=' characters in the string, and I think stringstream should be able to extract the portion up to the '=' character (getline with delimiter '=').

    Edit:
    By the way
    Code:
    ini >> foo;
    only reads up to the first whitespace. Use getline to read whole lines.

    With stringstreams you could do something like that
    Code:
    #include <string>
    #include <sstream>
    
    /* 
        Parses line, returns id and value by reference
        Returns whether successful
    */
       
    bool parse(const std::string& line, std::string& id, std::string& value)
    {
        std::stringstream ss(line);
        return std::getline(ss, id, '=') //id read successfully
            && std::getline(ss, value) //value read successfully
            && value.find('=') == std::string::npos //value doesn't contain '='
            && ss.eof(); //nothing left to read (unneeded if line is really one line)
    }
    Last edited by anon; 06-20-2007 at 08:48 AM.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Deployment and DLL/OCX Files?
    By dfghjk in forum C++ Programming
    Replies: 5
    Last Post: 06-16-2008, 02:47 AM
  2. Folding@Home Cboard team?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 398
    Last Post: 10-11-2005, 08:44 AM
  3. Playing wma files
    By maxorator in forum C++ Programming
    Replies: 4
    Last Post: 10-02-2005, 02:23 AM
  4. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  5. playing .mmf files
    By Ruski in forum Windows Programming
    Replies: 2
    Last Post: 06-17-2005, 09:49 PM