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 3355126
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:21:27+00:00 2026-05-18T02:21:27+00:00

I am trying to parse a table in the form of a text file

  • 0

I am trying to parse a table in the form of a text file using ifstream, and evaluating/manipulating each entry. However, I’m having trouble figuring out how to approach this because of omissions of particular items. Consider the following table:

NEW  VER  ID   NAME
1    2a   4    "ITEM ONE" (2001)
     1    7    "2 ITEM" (2002) {OCT}
     1.1  10   "SOME ITEM 3" (2003)
1         12   "DIFFERENT ITEM 4" (2004)
1    a4   16   "ITEM5" (2005) {DEC}

As you can see, sometimes the “NEW” column has nothing in it. What I want to do is take note of the ID, the name, the year (in brackets), and note whether there are braces or not afterwards.

When I started doing this, I looked for a “split” function, but I realized that it would be a bit more complicated because of the aforementioned missing items and the titles becoming separated.

The one thing I can think of is reading each line word by word, keeping track of the latest number I saw. Once I hit a quotation mark, make note that the latest number I saw was an ID (if I used something like a split, the array position right before the quotation mark), then keep record of everything until the next quote (the title), then finally, start looking for brackets and braces for the other information. However, this seems really primitive and I’m looking for a better way to do this.

I’m doing this to sharpen my C++ skills and work with larger, existing datasets, so I’d like to use C++ if possible, but if another language (I’m looking at Perl or Python) makes this trivially easy, I could just learn how to interface a different language with C++. What I’m trying to do now is just sifting data anyways which will eventually become objects in C++, so I still have chances to improve my C++ skills.

EDIT: I also realize that this is possible to complete using only regex, but I’d like to try using different methods of file/string manipulation if possible.

  • 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-05-18T02:21:27+00:00Added an answer on May 18, 2026 at 2:21 am

    If the column offsets are truly fixed (no tabs, just true space chars a la 0x20) I would read it a line at a time (string::getline) and break it down using the fixed offsets into a set of four strings (string::substr).

    Then postprocess each 4-tuple of strings as required.

    I would not hard-code the offsets, store them in a separate input file that describes the format of the input – like a table description in SQL Server or other DB.

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

Sidebar

Related Questions

I'm trying to parse an INI file using C++. Any tips on what is
I'm trying to parse a html page and extract 2 values from a table
I am trying to parse JSON in an Adobe Flex app, using http://www.mikechambers.com/blog/2006/03/28/tutorial-using-json-with-flex-2-and-actionscript-3/'>This Tutorial
I'm trying to parse some JSON using the JSon.Net library. The documentation seems a
I'm trying to parse a grammar in ocamlyacc (pretty much the same as regular
I'm trying to parse objects to XML in Delphi, so I read about calling
I have been trying to parse Java exceptions that appear in a log for
I'm trying to parse an international datetime string similar to: 24-okt-08 21:09:06 CEST So
I'm trying to parse an array of JSON objects into an array of strings
I'm trying to parse a simple string in C++. I know the string contains

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.