| | |
read text file into a structure
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2008
Posts: 16
Reputation:
Solved Threads: 0
Hello!
i have the following data in a file
student_id student_name maths_score english_score physics_score
can i use a nested structure to read the file?
if yes, how will i read the file into the structure?help me please
i have the following data in a file
student_id student_name maths_score english_score physics_score
can i use a nested structure to read the file?
C++ Syntax (Toggle Plain Text)
struct student { int id; char name[40]; }; struct score { int maths; int english; int physics; };
•
•
Join Date: Jan 2008
Posts: 3,832
Reputation:
Solved Threads: 501
•
•
•
•
Hello!
i have the following data in a file
student_id student_name maths_score english_score physics_score
can i use a nested structure to read the file?
if yes, how will i read the file into the structure?help me pleaseC++ Syntax (Toggle Plain Text)
struct student { int id; char name[40]; }; struct score { int maths; int english; int physics; };
C++ Syntax (Toggle Plain Text)
struct score { int maths; int english; int physics; }; struct student { int id; char name[40]; score studentScore; };
C++ Syntax (Toggle Plain Text)
student aStudent; ins >> aStudent.id; ins >> aStudent.name; ins >> aStudent.studentScore.math; ins >> aStudent.studentScore.english; ins >> aStudent.studentScore.physics;
•
•
Join Date: Jun 2007
Posts: 275
Reputation:
Solved Threads: 45
It might be best to read the file directly into the array of structs. Then when you sort the array by whatever field, all of the data for that student stays together. you can use the qsort() function, or if you want, store the structs in a list, and use the list.sort() function.
Last edited by dougy83; Mar 16th, 2008 at 4:41 am.
•
•
Join Date: Jan 2008
Posts: 3,832
Reputation:
Solved Threads: 501
•
•
•
•
if i have to sort the scores in maths, do i have to copy it to an array then sort it?
C++ Syntax (Toggle Plain Text)
student someStudents[100]; // miscellaneous code ins >> someStudents[i].studentScore.math;
![]() |
Similar Threads
- Reading in a *.csv file and loading the data into an Array (Java)
- Help!!!! Filtering A Text File (C++)
- Dynamic array (C++)
- Read comma separated data from a text file (C)
- Making arrays from text files (VB.NET)
- read text file (C)
- sourcing a python config file? (Python)
- How to delete a data structure in Builder 6.0? (C++)
- Read and writing strings from structures (C++)
Other Threads in the C++ Forum
- Previous Thread: decimal to binary in while loop..stuck
- Next Thread: Search string?
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph gui homeworkhelp iamthwee ifstream image input int java lib library list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






