Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8378647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:58:30+00:00 2026-06-09T15:58:30+00:00

i have a problem and i think the solution might be pretty easy but

  • 0

i have a problem and i think the solution might be pretty easy but im kinda stuck. I have some kind of config file wich im trying to parse in c++ to get some important values.

It looks like this:

info size=32 bold=0 italic=0 unicode=1 stretchH=100 smooth=1 aa=1 padding=0,0,0,0
common lineHeight=32 base=27 scaleW=1024 scaleH=28 pages=1 packed=0 alphaChnl=1
chars count=74
char id=32 x=837 y=15 width=3 height=1 xoffset=-1 yoffset=31 xadvance=8 page=0 chnl=15
char id=33 x=802 y=0 width=4 height=19 xoffset=2 yoffset=8 xadvance=8 page=0 chnl=15
char id=35 x=292 y=0 width=17 height=19 xoffset=0 yoffset=8 xadvance=16 page=0 chnl=15
char id=37 x=177 y=0 width=19 height=19 xoffset=-1 yoffset=8 xadvance=17 page=0
chnl=15
char id=38 x=216 y=0 width=18 height=19 xoffset=0 yoffset=8 xadvance=18 page=0 chnl=15

Info, common and chars a basic/global values. Every char line should be saved in an array (or vector) of structs with a similar format (x, y, height, offsetX, offsetY …)

Now i’ve tried getline() for example to get every line one by one and then make an istringstream with these lines to “search” those lines for the values i need.
Its worth noticing that iam not needing all those values i need a way to just save the one i need for every line.

Thanks in advance for any help here!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:58:32+00:00Added an answer on June 9, 2026 at 3:58 pm

    Each line is prefixed by the type of object.
    So your reader should read the first word off and then decide what object to read.

    std::ifstream  file("data.txt");
    std::string    type;
    while(file >> type)
    {
             if (type == "info")    { readInfo(file);}
        else if (type == "common")  { readCommon(file);}
        else if (type == "chars")   { readChars(file);}
        else if (type == "char")    { readChar(file);}
    }
    

    For each type of object you need to define a structure to hold the data.

    // char id=32 x=837 y=15 width=3 height=1 xoffset=-1 yoffset=31 xadvance=8 page=0 chnl=15
    struct CharData
    {
        int   id;
        int   x;
        int   y;
        int   width;
        int   height;
        int   xoffset;
        int   yoffset;
        int   xadvance;
        int   page;
        int   chnl;
    };
    

    Now you have to define a method to read the data. In C++ we use operator>> to read data from a stream.

    std::istream& operator>>(std::istream& stream, CharData& data)
    {
        // All the data is on one line.
        // So read the whole line (including the '\n')
        std::string        line;
        std::getline(stream, line);
    
        // convert the single line into a stream for parsing.
        // One line one object just makes it easier to handle errors this way.
        std::stringstream  linestream(line);
    
        // Assume the prefix type information has already been read (now looks like this)
        // id=32 x=837 y=15 width=3 height=1 xoffset=-1 yoffset=31 xadvance=8 page=0 chnl=15
        std::string   command;
        while(linestream >> command) // This reads one space separated command from the line.
        {
                 if (command.substr(0,3) == "id=")        {data.id       = atoi(&command[3]);}
            else if (command.substr(0,2) == "x=")         {data.x        = atoi(&command[2]);}
            else if (command.substr(0,2) == "y=")         {data.y        = atoi(&command[2]);}
            else if (command.substr(0,6) == "width=")     {data.width    = atoi(&command[6]);}
            else if (command.substr(0,7) == "height=")    {data.height   = atoi(&command[7]);}
            else if (command.substr(0,8) == "xoffset=")   {data.xoffset  = atoi(&command[8]);}
            else if (command.substr(0,8) == "yoffset=")   {data.yoffset  = atoi(&command[8]);}
            else if (command.substr(0,9) == "xadvance=")  {data.xadvance = atoi(&command[9]);}
            else if (command.substr(0,5) == "page=")      {data.page     = atoi(&command[5]);}
            else if (command.substr(0,5) == "chnl=")      {data.chnl     = atoi(&command[5]);}
        }
        return stream;
    }
    

    Repeat the processes for the other types you need to read. Then writting the read commands becomes simple:

    std::vector<CharData>    charVector;
    void readChar(std::istream& stream)
    {
        CharData     data;
        stream >> data;               // read the object from the stream
                                      // This uses the `operator>>` we just defined above.
    
        charVector.push_back(data);   // put the data item into a vector.
    }
    

    Repeat the processes for the other types.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think I have a big problem. I have a two projects solution. First
I have a problem which makes me crazy. I think it is very easy
i have a problem that i can't solve ! (sqlite3, but i think it
I think I have a problem with casting. $db = mysqli_connect('127.0.0.1','root','password','test'); if (! $db)
I think I have a problem in understanding the proper way of using MVC.
I have a problem with a template and pointers ( I think ). Below
Hi I have a problem in sending data from php to pdf. I think
I think I have a synchronization problem...It may be too basic..Please help.. I have
I think i have a basic problem in understanding the dojo toolkit. Well I
I have a security problem. I think to lock a table would be a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.