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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:06:00+00:00 2026-06-14T06:06:00+00:00

I have a data text file which contains this Map2D, [3, 2] Dot3D, [25,

  • 0

I have a data text file which contains this

Map2D, [3, 2]
Dot3D, [25, -69, -33], [-2, -41, 58]
Map3D, [6, 9, -50]
Map2D, [3, 2]
Dot3D, [7, -12, 3], [9, 13, 68]
Map3D, [6, 9, 5]
Map2D, [3, 2]
Dot3D, [70, -120, -3], [-29, 1, 268]
Dot3D, [7, 12, 3], [-9, 13, 68]
Map3D, [1, 3, 8]
Dot2D, [5, 7], [3, 8]

Basically the text file first data is the class name which i got 4 class

Map2D
Map3D
Dot2D
Dot3D

I was trying to write my own file manipulator so that my program can extract the data above and overload the extraction operator >> for each of the 4 class and then storing it into relevant object.

I was thinking of using vector, map, set or list to store . but for this how do i achieve what i want to do such as store into relevant object of the class.

I tried googling around on how to create my own file manipulator, but will be good if someone could show me some sample code and i can compile and execute it maybe in a test file then observe the output myself. I would like to use iomanip to do a overload on the >> operator

I have to use manipulator because i need create something like

I need to do something like

cout << "Input File Name";
cin >> readFile;

and perform all the data reading & object creation

I am sorry for all the trouble caused. then it will read the records line by line, then create the class and also the data in it.

Thanks for all your help!

  • 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-14T06:06:01+00:00Added an answer on June 14, 2026 at 6:06 am

    This is an example with std::cin. It should work just fine with a fstream. parsing your input is really nasty. Is it possible to remove the brackets(“[” amd “]”) from the input?

    #include <iostream>
    #include <string>
    #include <vector>
    #include <sstream>
    #include <algorithm>
    #include <c>
    
    class Map2D {
        std::vector<int> values;
    public:
        friend std::istream& operator>>(std::istream& in, Map2D m) {
            std::string i;
            in >> i;
            std::stringstream ss(i);
            std::getline(ss, i, '[');
            std::getline(ss, i, ',');
            ss >> i;
            std::cout << i << std::endl;
            in >> i;
            ss.str("");
            ss << i;
            i = i.substr(0, i.size()-1);
            ss >> i;
            std::cout << i << std::endl;;
        }
    };
    
    int main() {
        std::string type, file_name;
        std::cout << "Input File Name";
        std::cin >> file_name;
        std::fstream file(file_name.c_str());
        Map2D m;
        while (std::getline(std::cin, type, ',')) {
            if(type.find("Map2D") != std::string::npos) {
                file >> m;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text data file which contains text like this: [category.type.group.subgroup] - 2934:10,4388:20,3949:30
I have a text file which contains data. I want to set this data
I have a text file which contains data seperated by '|'. I need to
I have a text file which contains data I need to preload into a
I have a text file which contains columns of data that are either integer,
I have a Text file which contains data (4 to 5 paragraph) and then
I have to import a text file with data which contains double quotes. Actually
I have a text file input which contains data as below. How can I
Hi I have a text file which contains some numerical data. Of that text
I have a text file with 50k+- lines and each line contains data which

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.