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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:12:08+00:00 2026-05-27T17:12:08+00:00

I have data in the following format in a file ( p1, p2 )

  • 0

I have data in the following format in a file
( p1, p2 ) (p3, p4 ) ( p5, p6 )

How do i read this in C++, I can read a line and parse it , but I was looking for some C++ stl way to read this kind of format.

  • 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-27T17:12:09+00:00Added an answer on May 27, 2026 at 5:12 pm

    It depends on the format you want to represent the data in your program. One way is to have a struct with a custom stream-extraction operator:

    struct Data {
        int val1; // just assuming int for the data-type
        int val2;
    };
    
    std::istream & operator>>(std::istream& input, Data & obj) {
        input.ignore(2, '('); // skip all including opening brace
        input >> obj.val1;
        input.ignore(2, ','); // skip comma
        input >> obj.val2;
        input.ignore(2, ')'); // skip closing brace
        return input;
    }
    

    As @Seth Carnegie demonstrates in an answer to a similar question, you can also use INT_MAX to make sure you skip enough – however, using std::numeric_limits<std::streamsize>::max() would be even better.

    Then you can read all the contents of the file like this:

    std::vector<Data> all_data;
    std::ifstream input_file("your_file.txt");
    std::copy(std::istream_iterator<Data>(input_file), 
              std::istream_iterator<Data>(),
              std::back_inserter(all_data));
    

    Here is a complete working example.

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

Sidebar

Related Questions

I have a text file containing the data in following format 12345 Abdt3 hy45d
I have a file in the following format: Data Data Data [Start] Data I
I have a XML file with the following data format: <net NetName=abc attr1=123 attr2=234
I have a txt file which contains data in the following format: X1 Y1
I have a file which has data in the following format A B -----
Looking for a way to read the following config file sample using a multi
I have a data file in the following format: 1234567890 asdfgasdfgsdfgetsegzdfbcvbsdfg 9876543210 dfgdegdrdatkeqlkrmgda the
I have data in the following format: 4:How do you do? 10:Happy birthday 1:Purple
If I have data in the following format id subid text 1 1 Hello
I have a data with the following format: foo<tab>1.00<space>1.33<space>2.00<tab>3 Now I tried to sort

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.