473,765 Members | 2,121 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Comma deliminated reading

13 New Member
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 2475
CJK
13 New Member
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
4318
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 respect to reading 'long double's from a stream separated by comma. #include <iostream>
1
6692
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 processing. I am having no luck at all finding different routines written in C to read delimited files of any kind. I have a few ideas of how I might go about this but I bet I'm re-inventing the wheel and there already exists some efficient code out...
3
1654
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 comma. For example: BENL LT, RAT LT At the moment, I've got the VBA bits working on the single ID stuff, but, should it come across a list like the above,
4
13304
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
3294
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. Looks like I need a loop or something. What would be the best way to take a comma separated string to initialize a byte array using cs?
1
1725
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 able to find to read the values all involve StreamReader, and I can't figure out how to use this. Since I'm using MFC, I'm using CFile instead. Also, none of the methods seem to come with a method for error catching. I want my program to be...
3
7128
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 export it into a text file. Is there any s/w out there I could use? I am not much of a programmer but I heard I could use VBA to get this done. Any help with the code will be appreciated. Thanks
6
2611
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) ? sizeof (STR) - 1 : 0)
22
3599
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 generation is there any other purpose than this, if so why ...????
0
9568
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9398
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10007
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7375
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5275
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2805
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.