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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:10:11+00:00 2026-06-14T05:10:11+00:00

I have a text file, the contents are Point1, [5, 6] Line2, [1, 2,

  • 0

I have a text file, the contents are

Point1, [5, 6]
Line2, [1, 2, 3], [-5, 55, 33]
Point2, [5, 3, 1]
Line1, [1, 2], [5, 7]

I will do comparisions, like the first variable (Point1, Line2, Point2, Line1)

If it is point1, it will be stored into point 1 array, and 5 being set as x, and y being set as 6.

How do I set the delimter to commas and also the ‘[‘ and ‘]’. I just need the variable Point1, 5 and 6 to store them accordingly.

  • 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-14T05:10:12+00:00Added an answer on June 14, 2026 at 5:10 am

    I would solve this problem the simplest way possible – read the file using getline and then replace all the occurances of ,, [ and ] with spaces. Then you can read all the input using std::istringstream from <sstream>. You could also use regular expressions(if you use boost or c++-11), but I believe what I suggest should do the job.

    EDIT: here is an example how to do what I suggest. I will only show you how to input points, to handle lines as well you will have to add an if statement based on name.

    #include <iostream>
    #include <string>
    #include <sstream>
    
    using namespace std;
    
    int main() {
      string line;
    
      while (getline(cin, line)) {
        for (unsigned i = 0; i < line.size(); ++i) {
          if (line[i] == '[' || line[i] == ']' || line[i] == ',') {
            line[i] = ' ';
          }
        }
        istringstream in(line);
    
        string name;
        double x,y;
        in >> name >> x >> y; // Point1 <x> <y>
        ... do something with the point...
      }
    
      return 0;
    }
    

    Also you can use replace_if from <algorithm> to replace the symbols, but I decided it will be easier for you to understand this solution.

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

Sidebar

Related Questions

I have text file with some stuff that i would like to put into
I have text file with something like first line line nr 2 line three
I have a text file named num.txt who's only contents is the line 123
I have text file, like FILED AS OF DATE: 20090209 DATE AS OF CHANGE:
I have text file with entries like 123 112 3333 44 2 How to
I have a file, its contents are identical. It is passed into gzip and
I have a description text file with content constructed in such manner: Book title
okay, so i have a text file with example content below line1with some random
I have a dynamic text file that picks content from a database according to
I have Text file that contains data separated with a comma , . How

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.