473,387 Members | 1,673 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,387 software developers and data experts.

help reading file in and sorting it

7
I thought I understood how to do this, but have spent all weekend and haven't gotten anywhere, can someone please help?? I'm desparate.

This is my main: partNum and dept are strings, price is a double.

Expand|Select|Wrap|Line Numbers
  1. while (!inData.eof())
  2. {
  3.       readDataItem(inData, partNum, dept, price);
  4. }
  5.  
  6.  
After I read the file in how can I get it into separate arrays so I can sort it?

This is my header file
Expand|Select|Wrap|Line Numbers
  1. class Item
  2. {
  3.     friend ostream& operator<<(ostream& cout, Item& );
  4.  
  5. public:
  6.     void print() const;
  7.  
  8.     Item(string* p, string* d, double* pr);
  9.  
  10.     Item();
  11.  
  12. private:
  13.     string* part;
  14.     string* deptNo;
  15.     double* itemPrice;
  16. };
  17.  
This is my .cpp file
Expand|Select|Wrap|Line Numbers
  1. #include "Item.h"
  2.  
  3. Item::Item(string* p, string* d, double* pr)
  4. {
  5.     part = p;
  6.     deptNo = d;
  7.     itemPrice = pr;
  8. }
  9.  
  10. Item::Item()
  11. {}
  12.  
  13. ostream& operator<<(ostream& osObject, Item& i)
  14. {
  15.     osObject<<i.part;
  16.     osObject<<" ";
  17.     osObject<<i.deptNo;
  18.     osObject<<" ";
  19.     osObject<<i.itemPrice<<endl;
  20. return osObject;
  21. }
  22.  
Dec 11 '06 #1
1 1432
Banfa
9,065 Expert Mod 8TB
I suspect that declaring you member variables as pointers

Expand|Select|Wrap|Line Numbers
  1.     string* part;
  2.     string* deptNo;
  3.     double* itemPrice;
  4.  
is a mistake. You are going to have to do a lot of memory operations to support these pointers and I think you could use actual data members rather than pointers.

You say you are having trouble reading a file but you havn't given the file format.
Dec 15 '06 #2

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

Similar topics

6
by: Kevin T. Ryan | last post by:
Hi All - I'm not sure, but I'm wondering if this is a bug, or maybe (more likely) I'm misunderstanding something...see below: >>> f = open('testfile', 'w') >>> f.write('kevin\n') >>>...
5
by: Dr. Ann Huxtable | last post by:
Hello All, I am reading a CSV (comma seperated value) file into a 2D array. I want to be able to sort multiple columns (ala Excel), so I know for starters, I cant be using the array, I need...
8
by: hothead098 | last post by:
ASSIGNMENT (4) USING AND MANIPUPATING ARRAYS (Chapter 10 material) For this assignment you are to: 1) Create and manage arrays a) One of type integers (containing 10 elements). b) One of...
1
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
5
by: Sam | last post by:
Hi, I have one table like : MyTable {field1, field2, startdate, enddate} I want to have the count of field1 between startdate and enddate, and the count of field2 where field2 = 1 between...
3
by: Don | last post by:
I'm using Access 2000. My database collects lots and lots of data. One aspect of that is to collect dimensional data from multiple checks during the day. The way I've done that is to have a...
7
by: Steve Chow | last post by:
hi, i'm reading a binary data file, which is basically a list of 7296 offsets pointing to data blocks which represent scanlines containing three numbers; leftx, id, rightx. i can read these fine...
4
by: ndedhia1 | last post by:
I am reading in a file to see what delays I am getting on what IP address: QuoteBlockTiming exceeded 1000 ms: 1684 --- Fri Nov 06 06:09:10 CST 2009 170.137.94.95 Class key = 649126730 block...
5
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
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,...

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.