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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:27:40+00:00 2026-06-18T01:27:40+00:00

The file that I am reading from contains data about cities. I am wondering

  • 0

The file that I am reading from contains data about cities. I am wondering how I can extract just the data I want and apply it to my city objects. Below is my city class.

    #include <iostream>
    #include <string>
    #include <cstdlib>
    #include "City.h"
    using namespace std;

    /*
     * Define the constructor for the class 
     */
    City::City(string city_name, string state, int longitude, int latitude, int population) {
        this->city_name = city_name;
        this->state     = state;
        this->longitude = longitude;
        this->latitude = latitude;
        this->population = population;
    }

    /*
     *Accessors
     */ 
    string City::getCity() { 
                return city_name; 
        }

    string City::getState() { 
            return state; 
        }

    int City::getLongitude() {
            return longitude;
        }

    int City::getLatitude() {
            return latitude;
        }

    int City::getPopulation() {
            return population;
        }

    /*
     * Mutators 
     */ 
    void City::setCity(string city_name) {
            this->city_name = city_name;
        }
    void City::setState(string state) {
            this->state = state;
        }
    void City::setLongitude(int longitude) {
            this->longitude = longitude;
        }
    void City::setLatitude(int latitude) {
            this->latitude = latitude;
        }
    void City::setPopulation(int population) {
            this->population = population;
        }


    /*
     * Sorting methods
     */
    void City::sortByCity() {
            // Code to sort cities by city name
    }

    void City::sortByLongitude() {
            // Code to sort cities by longitude
    }  

Here is an example of the type of text the file contains that I want to read from

1063061|OH|Tobias|ppl|Marion|39|101|404118N|0830359W|40.68833|-83.06639|||||985|||Monnett
1063062|OH|Todds|ppl|Morgan|39|115|393129N|0815049W|39.52472|-81.84694|||||983|||Stockport

My question is how do I exclude the ‘|’ characters from my file input stream? As well as how do I extract only the strings that I need. (Ex. Tobias as city_name or OH for state) in order to create my city objects. Thank You

  • 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-18T01:27:40+00:00Added an answer on June 18, 2026 at 1:27 am

    use getline with delimiter character ‘|’ and write an inputting sequence adapted to your formatted input data

    ifstream myfile ("input.txt");
    string s;
    getline (myfile,s,'|')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading data from a file that has, unfortunately, two types of character
I am reading in data from a file that has three columns. For example
I have a file that contains about 200,000 long values that I want to
I'm trying to convert a string that I'm reading from a file to lowercase
I have a C++ program that is reading in info from a file, that
I am working on a program that requires reading in integers from a file
This is my problem: I'm reading data from an Excel file on a .NET
I have a file that contains 600K+ lines of stuff I want to process.
I have a custom file type that I'm reading from and writing to within
I have an excel spreadsheet which contains addresses. I'm reading the data from the

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.