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

  • Home
  • SEARCH
  • 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 72031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:58:51+00:00 2026-05-10T19:58:51+00:00

I have the following file/line: pc=1 ct=1 av=112 cv=1100 cp=1700 rec=2 p=10001 g=0 a=0

  • 0

I have the following file/line:

pc=1 ct=1 av=112 cv=1100 cp=1700 rec=2 p=10001 g=0 a=0 sz=5 cr=200 pc=1 ct=1 av=113 cv=1110 cp=1800 rec=2 p=10001 g=0 a=10 sz=5 cr=200 

and so on. I wish to parse this and take the key value pairs and put them in a structure:

struct pky {     pky() :       a_id(0),       sz_id(0),       cr_id(0),       cp_id(0),       cv_id(0),       ct_id(0),       fr(0),       g('U'),       a(0),       pc(0),       p_id(0)     { } }; 

wherein either all the structure fields are used or some might be omitted.

How do I create a C++ class, which will do the same? I am new to C++ and not aware of any functions or library which would do this work.

Each line is to be processed, and the structure will be populated with one line each time and used, before it is flushed. The structure is later used as a parameter to a function.

  • 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. 2026-05-10T19:58:51+00:00Added an answer on May 10, 2026 at 7:58 pm

    You can do something like this:

    std::string line; std::map<std::string, std::string> props; std::ifstream file('foo.txt'); while(std::getline(file, line)) {     std::string token;     std::istringstream tokens(line);     while(tokens >> token) {         std::size_t pos = token.find('=');         if(pos != std::string::npos) {             props[token.substr(0, pos)] = token.substr(pos + 1);         }     }      /* work with those keys/values by doing properties['name'] */     Line l(props['pc'], props['ct'], ...);      /* clear the map for the next line */     props.clear(); } 

    i hope it’s helpful. Line can be like this:

    struct Line {      std::string pc, ct;      Line(std::string const& pc, std::string const& ct):pc(pc), ct(ct) {      } }; 

    now that works only if the delimiter is a space. you can make it work with other delimiters too. change

    while(tokens >> token) { 

    into for example the following, if you want to have a semicolon:

    while(std::getline(tokens, token, ';')) { 

    actually, it looks like you have only integers as values, and whitespace as delimiters. you might want to change

        std::string token;     std::istringstream tokens(line);     while(tokens >> token) {         std::size_t pos = token.find('=');         if(pos != std::string::npos) {             props[token.substr(0, pos)] = token.substr(pos + 1);         }     } 

    into this then:

        int value;     std::string key;     std::istringstream tokens(line);     while(tokens >> std::ws && std::getline(tokens, key, '=') &&            tokens >> std::ws >> value) {             props[key] = value;     } 

    std::ws just eats whitespace. you should change the type of props to

    std::map<std::string, int> props; 

    then too, and make Line accept int instead of std::string’s. i hope this is not too much information at once.

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

Sidebar

Ask A Question

Stats

  • Questions 74k
  • Answers 74k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer You can do this fairly easily in either a controller… May 11, 2026 at 2:24 pm
  • added an answer For a GridView you can use the setOnItemClickListener method to… May 11, 2026 at 2:24 pm
  • added an answer I've never used CppUnit, so not sure how protectors work.… May 11, 2026 at 2:24 pm

Related Questions

I have the following file: abcde kwakwa <0x1A> line3 linllll Where <0x1A> represents a
I have a file that contains this kind of paths: C:\bad\foo.c C:\good\foo.c C:\good\bar\foo.c C:\good\bar\[variable
Let's say I have the following XML file <a id=123> <b type=foo value=1 />
After years of using the big ugly MFC ASSERT macro, I have finally decided

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.