1) Read the file into memory (such as an array or vector)
2) Modify the memory to delete the unwanted information
3) Write the memory back to file
Hope this helps.
Noted
can you help me to understand more about the tip number 1?
Sure.
Presumably you have a file of Teachers (
"teachers.txt" or something).
Allen Birch
0000/00/00
Jim Brown
0000/00/00
Jennifer Black
0000/00/00
|
You will need something to keep track of all those teachers, like a vector (preferred) or an array.
1 2 3
|
std::vector<Teacher> teachers;
|
constexpr int MAX_NUM_TEACHERS 50;
Teacher teachers[MAX_NUM_TEACHERS];
int num_teachers = 0; |
Create yourself a function to read the teachers into memory:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
void load_teachers(
const std::string& filename,
std::vector <Teachers> & teachers )
{
std::ifstream f( filename );
Teacher teacher;
while (
getline( f, teacher.name )
and getline( f, teacher.date ))
{
teachers.push_back( teacher );
}
}
|
void load_teachers(
const std:string& filename,
Teacher* teachers, int* num_teachers )
{
std::ifstream f( filename );
Teacher teacher;
while ((*num_teachers < MAX_NUM_TEACHERS)
and getline( f, teacher.name )
and getline( f, teacher.date ))
{
teachers[(*num_teachers)++] = teacher;
}
} |
You can the load your teachers from file:
|
load_teachers( "teachers.txt", teachers );
|
load_teachers( "teachers.txt", teachers, &num_teachers ); |
Good luck!
Last edited on
owkkk i m going to study taht
excuse me i plan to use array as to keep track of all those teachers
can you show me how to start?