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

  • Home
  • SEARCH
  • 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 7948325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:41:37+00:00 2026-06-04T01:41:37+00:00

I am working on an addressbook program, which reads data from a csv file

  • 0

I am working on an addressbook program, which reads data from a csv file of the following format

“last name”, “first name”, “nickname”, “email1”, “email2”, “phone1”, “phone2”,“address”, “website”, “birthday”, “notes”

I have read the file using getline in the following way:

   if(!input.fail())
     { 
       cout<<"File opened"<<endl;
       while(!input.eof())
       {

     getline(input,list) ; 
     contactlist.push_back(list);
     token=con.tokenize(list);  // NOT SURE IF I'm doing this right..am I?

        }
    }

and I’m using the tokenize member function of one of my classes contact, which looks like this

// member function reads in a string and tokenizes it
vector<string>Contact::tokenize(string line)
{
    int x = 0, y = 0,i=0;

string token;
vector<string>tokens;
while(x < line.length() && y < line.length())
{

    x = line.find_first_not_of(",", y);
    if(x >=0 && x < line.length())
    {

        y = line.find_first_of(",", x);
        token = line.substr(x, y-x);
        tokens.push_back(token);
        i++;
    }
}

}     

I now need to read the tokenized vector into a private vector member variable of another class and also need to read them into individual private variable of first name,lastname …note of class Contact.How do I read them into private vector member variable of a classtype and how would I call them in the member functions that would do evaluations such sorting adding a contact using the vectors.

and in total I have 2 header files Contact and addressbook with their respective implementation files and a main.

Also If you happen to have a clear concept accessing vectors of vectors/vectors within a vector like I have contactlist and token here in main

  • 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-04T01:41:38+00:00Added an answer on June 4, 2026 at 1:41 am

    First you should separate your tokenize function from the contact class. It’s not in the responsibility of a contact to read a csv row. So extract this method to a new tokenizer class, just write a free tokenize function or use a solution like boost tokenizer.

    With the generated tokens you can create a contact instance or pass it to another class.

    struct Contact
    {
      std::string firstName, lastName, email;
    
      /// Constructor.
      Contact(const std::string& firstName, 
          const std::string& lastName, 
          const std::string& email);
    };
    
    struct AnotherClass
    {
      /// Constructor.
      AnotherClass(const std::vector<std::string>& tokens) :
         privateVector(tokens)  {}
    
      /// Construction with input iterators
      template<typename Iter>
      AnotherClass(Iter firstToken, Iter lastToken) :
        privateVector(firstToken, lastToken) {}
    
    private:
      std::vector<std::string> privateVector;
    };
    
    
    int main()
    {
      std::string line = ReadLine();
      std::vector<std::string> tokens = tokenize(line);
    
      Contact newContact(tokens[0], tokens[1], tokens[2]);
    
      AnotherClass wathever(begin(tokens), end(tokens));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Application which displays a Chart, which is filled with data from
I have a very basic CSV file upload module working to bulk upload my
Working on my first Rails project, I used Ryan Bates' Nifty-Generators to create the
First of all, here's the full source code: http://pastebin.com/5teGNrPC *> IDENTIFICATION DIVISION. PROGRAM-ID. CAddress.
I am deleting contacts from addressbook programmatically. I got error There's already an instance
I've been working on laying out the data structure for an application I'm working
I am working with a simple address book in which i have separate lists
I need to extract records from a table, copy the data to a second
Working on some code and I'm given the error when running it from the
in an application I'm working on, I need to interact with iPhone's AddressBook. Currently,

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.