473,409 Members | 1,954 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,409 software developers and data experts.

Comma deliminated reading

13
this is what i have so far:
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <fstream>
  5.  
  6. using namespace std;
  7.  
  8. class Person
  9. {
  10. protected: string o_name;
  11.  
  12. public:
  13.     Person(string name)
  14.     {
  15.         this->o_name = name;
  16.     }
  17.     bool operator==(const Person& obj) const;
  18.     bool operator!=(const Person& obj) const;
  19. };
  20.  
  21. bool Person::operator ==(const Person& obj) const
  22. {
  23.     return (obj.o_name == this->o_name);
  24. }
  25. bool Person::operator !=(const Person &obj) const
  26. {
  27.     return (obj.o_name != this->o_name);
  28. }
  29.  
  30.  
  31. class Worker: public Person
  32. {
  33. friend ostream& operator<<(ostream&, const Worker &); 
  34. friend istream& operator>>(istream&, Worker &); 
  35.  
  36. private:
  37.     string workPlace;
  38.     int age;
  39. public:
  40.     Worker(string name, string w_wP, int w_a): Person(name)
  41.     {
  42.         workPlace = w_wP;
  43.         age = w_a;
  44.     }
  45.     string getName() const;
  46.     string getWorkPlace() const;
  47.     int getAge() const;
  48.     void print() const;
  49. };
  50. string Worker::getName() const
  51. {
  52.     return o_name;
  53. }
  54. string Worker::getWorkPlace() const
  55. {
  56.     return workPlace;
  57. }
  58. int Worker::getAge() const
  59. {
  60.     return age;
  61. }
  62. void Worker::print() const
  63. {
  64.     cout << "Name = " << o_name
  65.         << "; WorkPlace = " << workPlace
  66.         << "; Age = " << age;
  67. }
  68. ostream& operator<<(ostream& osObject, const Worker& worker) 
  69.    osObject <<"Name = " << worker.o_name << "; Work Place = " << worker.workPlace << "; Age = " << worker.age; 
  70.    return osObject; 
  71. istream& operator>>(istream& isObject, Worker& worker) 
  72.    isObject >> worker.o_name >> worker.workPlace >> worker.age; 
  73.    return isObject; 
  74.  
  75.  
  76. int main()
  77. {
  78.     string w_name, w_name2;
  79.     string w_workPlace, w_workPlace2;
  80.     int w_age, w_age2;
  81.     char ch;
  82.  
  83.     cout << "Enter name, work place and age, comma seperated : ";
  84.     getline(cin, w_name, ',');
  85.     getline(cin, w_workPlace, ',');
  86.     cin >> w_age;
  87.  
  88.     cin.get(ch);
  89.  
  90.     cout << "Enter name, work place and age, comma seperated : ";
  91.     getline(cin, w_name2, ',');
  92.     getline(cin, w_workPlace2, ',');
  93.     cin >> w_age2;
  94.  
  95.     cin.get(ch); 
  96.  
  97.  
  98.     Worker w1(w_name, w_workPlace, w_age);
  99.     Worker w2(w_name2, w_workPlace2, w_age2);
  100.  
  101.     if(w1 == w2)
  102.     {
  103.         cout << "They have the same name" << endl;
  104.     }
  105.     else if(w1 != w2)
  106.     {
  107.         cout << "They do not have the same name" << endl;
  108.     }
The problem i have is how do i read a text file that has comma deliminated values in it and then store the information in a worker object. ANy help greatly appreicated
Oct 21 '06 #1
1 2453
CJK
13
like if the file had the values:

mark,xwork,34
Oct 22 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Rakesh Sinha | last post by:
I have a very trivial question. But I searched in google / archives of this group to get the answer, checked the C++ FAQ - but did not precisely what I was looking for. The problem is with...
1
by: John B. Lorenz | last post by:
I'm attempting to write an input routine that reads from a comma delimited file. I need to read in one record at a time, assign each field to a field array and then continue with my normal...
3
by: Gary Smith | last post by:
Hi, I've got a field that contains a list of rooms. In most cases, this contains a single ID. However, under some circumstances, the field may contain a list of two IDs which are broken by a...
4
by: Hilary Cotter | last post by:
Thanks for all the help you gave me yesterday. here is another question. I have a comma delimited file called redirect.txt which looks like this test, /test.htm test 123,/test123.htm
2
by: pesso | last post by:
I have a string that contains the following: string s = "130,41,43,178,41,17,6,78,244,35,202,144,115"; They are comma separated byte numbers, and I need to initialize my byte array with them....
1
by: ungvichian | last post by:
So, right now I'm writing a program in VC++.Net with MFC, and one of the steps involves reading numeric values from a comma delimited file (like 4.56, 2.44, 3.453 etc.). The only methods I've been...
3
by: Avi | last post by:
I need to create a text file that has the data from the 10 tables in the database. The number of fields in the tables exceeds 255 and so I cannot make a new table with all the fields and then...
6
by: pedroalves | last post by:
Hi all, This is not a question about how to #define COMMA , Please keep reading. Recently in binutils, we introduced a macro like this: #define STRING_COMMA_LEN(STR) \ (STR), ((STR) ?...
22
by: aarklon | last post by:
Hi all, why does C language permits an extra comma in initializer list ex:- int days = { 31,28.31,30,31,30, 31,31,30,31,30,31, } i have heard it is for the purpose of automatic code...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.