Newbie Question, your help is needed.

Hello,
i'm working on an assignment for school.
i'm doing in visual c++ using borland.
i have a requirement to do the following:
1. Load Given a txt file which has a number of records (not specified) of student IDs and their date of enrollment.
2. Ability to filter Students by their ID
3. Ability to filter Students by Date of enrollment
4. Show the filtered result.
Below is an example of one line of the mentioned text file:
//Student ID, Date Enrolled,Name Abreviation
01368,2010-11-29,Ru88

What i've done so far:

1. Created visually the needed setup as such:

i. ComboBox (contains Student IDs, which i've added manually)
ii. DateTimePicker (added two with name: From and To)
iii. RadioButton (Labeled as ALL records, DATEdResult( which will set the DATETimePIcker to enabled and visible to show a specific date)
iV. StringGrid.
v. main menu with open dialog.

What i need advice with:

1. how can i load the text file in a way that i can take the comma as a delimiter. in other words, how can i sort by date (given that date is the second field.

3. am i correct to use stringgrid? would a memo be better suited for just showing the output?

Thank you for you advice in advance.


Last edited on
The GUI is up to you. However, to set a deliminator, use getline(a_file_stream, a_string, ',');. This will extract data from the file into the string until it hits the deliminator, in this case, a comma.
thanks for your reply.
so if i understood correctly, it'll retrieve each field and set it in it's own string.
though how can i reference those strings for filtering?
i need to sort them by date. is there a way to sort the mentioned strings?
For the date, I would suggest setting '-' as the deliminator. Then, use stringstream to extract the numbers into some variables. Then you would sort them like any other numbers.

To access the string, simply access it like you would any other variable.
Why do all of that ModShop? Numbers as strings can still be sorted by value since even as chars they have relative numerical equivalent values. You just can't do math with them and expect to get a number back as a result.

I personally wouldn't treat the date seperatly, just read the whole thing in as a string and keep the deliminator as a comma.

Also store the data from the file in a resizable container, I usually suggest a vector since it works in every case I've come across. http://www.cplusplus.com/reference/stl/vector/
Last edited on
Because technically, "2010-1-1" is not the same as "2010-01-01" and unless you can make sure that is is in the second form and not the first, you'll have some issues when comparing between two digits and one digit.
@ LB: That only matters if the file you're reading from mixes the two formats up. Otherwise as long as the data is consistant the results will be as well.
Topic archived. No new replies allowed.