PLZ HELP !! program is crashing .

am posting my code below....plz ignore the comments.THEY were only meant to help me in coding.I get no errors or warnings when i buid this code.but it crashes when i finish inputing values to the function add_tchr..which can be called using choice 1 in the first output window.i get error message PROGAM HAS STOPPED WORKING UNEXPECTEDLY. in the logs i get this--

Process terminated with status -1073741819

plz help....SUggest how can i make my code work.(AS MY CODE IS EXCEEDING WORD LIMIT ,SO I AM POSTING IT IN TWO PARTS).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
 /*read_data(istream &is)   // public member function**
    {
        is >> tchr_Id >> no_fprd >> ws;
        is.getline(name, sizeof(name));
        is.getline(tchr_sub, sizeof(tchr_sub));
        for(int z=0;z<8;++z)
        {
          getline(MO[z]);
          getline(TU[z]);
          getline(WE[z]);
          getline(TH[z]);
          getline(FR[z]);
          getline(SA[z]);



        }
    }
*/
#define STACKSIZE 20000
#include<iostream>
#include<fstream>
#include<cctype>
#include<iomanip>
#include<string.h>
using namespace std;
class teacher
{
    int tchr_Id,no_fprd;
    char name[30],tchr_sub[15];
    string MO[8],TU[8],WE[8],TH[8],FR[8],SA[8];
public:
    void add_tchr();                        // done and debugged.
    void update_tchr();                     // done and debugged.
    void expand_tchr() const;               // done but issues with memory....to be debugged.   WORKS FINE TILL 5th LOOP..prob while 6th.
    void find_tchr();                       //done....to be tested with DFH.
    void show_all();                        //done....to be tested with DFH.
    int ret_tchrId() const;
    void create_tchr(ostream &os)
    {
        os << tchr_Id << ' ' << no_fprd << endl;
        os << name << endl;
        os << tchr_sub << "\n";

        for(int z=0;z<8;++z)
        {
          os << MO[z] << endl;
          os << TU[z]  << endl;
          os << WE[z]  << endl;
          os << TH[z]  << endl;
          os << FR[z]  << endl;
          os << SA[z]  << endl;


        }
    }
};
void teacher::add_tchr()
{
    no_fprd=0;
    cout<<"\n\tENTER TEACHER ID No.---\t";
    cin>>tchr_Id;
    cin.ignore();
    cout<<"\n\n\tENTER TEACHER's NAME---\t";
    gets(name);
    cout<<"\n\n\tENTER TEACHER's SUBJECT---\t";
    gets(tchr_sub);
    cout<<"\n\n\t\tPlease enter the teacher's routine according to the following instructions---\n\n  ";
    cout<<"ENTER THE STANDARD AT WHICH TEACHER HAS CLASS ON MONDAY PERIOD \n\n";
    for(int z=0;z<8;++z)
    {
        cout<<z+1<<" :  \t";
        cin>>MO[z];cout<<endl;
        if(MO[z]=="f"||MO[z]=="F")
            {++no_fprd;
            MO[z]="FREE";}
    }
    cout<<"ENTER THE STANDARD AT WHICH TEACHER HAS CLASS ON TUESDAY PERIOD \n\n";
    for(int y=0;y<8;++y)
    {
        cout<<y+1<<" :  \t";
        cin>>TU[y];cout<<endl;
        if(TU[y]=="f"||TU[y]=="F")
             {++no_fprd;
             TU[y]="FREE";}
    }
    cout<<"ENTER THE STANDARD AT WHICH TEACHER HAS CLASS ON WEDNESDAY PERIOD \n\n";
    for(int x=0;x<8;++x)
    {
        cout<<x+1<<" :  \t";
        cin>>WE[x];cout<<endl;
        if(WE[x]=="f"||WE[x]=="F")
              {++no_fprd;
              WE[x]="FREE";}
    }
    cout<<"ENTER THE STANDARD AT WHICH TEACHER HAS CLASS ON THURSDAY PERIOD \n\n";
    for(int w=0;w<8;++w)
    {
        cout<<w+1<<" :  \t";
        cin>>TH[w];cout<<endl;
        if(TH[w]=="f"||TH[w]=="F")
             {++no_fprd;
             TH[w]="FREE";}
    }
    cout<<"ENTER THE STANDARD AT WHICH TEACHER HAS CLASS ON FRIDAY PERIOD \n\n";
    for(int t=0;t<8;++t)
    {
        cout<<t+1<<" :  \t";
        cin>>FR[t];cout<<endl;
        if(FR[t]=="f"||FR[t]=="F")
              {++no_fprd;
              FR[t]="FREE";}
    }
     cout<<"ENTER THE STANDARD AT WHICH TEACHER HAS CLASS ON SATURDAY PERIOD \n\n";
    for(int u=0;u<8;++u)
    {
        cout<<u+1<<" :  \t";
        cin>>SA[u];cout<<endl;
        if(SA[u]=="f"||SA[u]=="F")
              {++no_fprd;
              SA[u]="FREE";}
    }

}
void teacher::update_tchr()
{
    no_fprd=0;
    cout<<"\n\nTEACHER ID number :---\t\t : "<<tchr_Id;
	cout<<"\nENTER NEW TEACHER's NAME :---\t\t ";
	cin.ignore();
	gets(name);
	cout<<"\nENTER NEW TEACHER's SUBJECT :--- ";
	cin.ignore();
	gets(tchr_sub);
	cout<<"\n\n\t\tPlease enter the new teacher's routine according to the following instructions---\n\n\t\t";
    cout<<"ENTER THE STANDARD AT WHICH NEW TEACHER HAS CLASS ON MONDAY PERIOD \n\t\t\t";
    for(int z=0;z<8;++z)
    {
        cout<<z+1<<" :  \t";
        cin>>MO[z];cout<<endl;
        if(MO[z]=="f"||MO[z]=="F")
            {++no_fprd;
            MO[z]="FREE";}
    }
    cout<<"ENTER THE STANDARD AT WHICH NEW TEACHER HAS CLASS ON TUESDAY PERIOD \n\t\t\t";
    for(int y=0;y<8;++y)
    {
        cout<<y+1<<" :  \t";
        cin>>TU[y];cout<<endl;
         if(TU[y]=="f"||TU[y]=="F")
             {++no_fprd;
             TU[y]="FREE";}
    }
    cout<<"ENTER THE STANDARD AT WHICH NEW TEACHER HAS CLASS ON WEDNESDAY PERIOD \n\t\t\t";
    for(int x=0;x<8;++x)
    {
        cout<<x+1<<" :  \t";
        cin>>WE[x];cout<<endl;
        if(WE[x]=="f"||WE[x]=="F")
              {++no_fprd;
              WE[x]="FREE";}
    }
    cout<<"ENTER THE STANDARD AT WHICH NEW TEACHER HAS CLASS ON THURSDAY PERIOD \n\t\t\t";
    for(int w=0;w<8;++w)
    {
        cout<<w+1<<" :  \t";
        cin>>TH[w];cout<<endl;
        if(TH[w]=="f"||TH[w]=="F")
             {++no_fprd;
             TH[w]="FREE";}
    }
    cout<<"ENTER THE STANDARD AT WHICH NEW TEACHER HAS CLASS ON FRIDAY PERIOD \n\t\t\t";
    for(int t=0;t<8;++t)
    {
        cout<<t+1<<" :  \t";
        cin>>FR[t];cout<<endl;
        if(FR[t]=="f"||FR[t]=="F")
              {++no_fprd;
              FR[t]="FREE";}
    }

}
void teacher::expand_tchr() const
{
    cout<<"\n\n\n\n\n**********************************************************************\n";          //function yet to be debugged.
    cout<<"\n**********************************************************************\n";                           //issues with memory space.
    cout<<"\n\n\tTEACHER ID number :---\t\t : "<<tchr_Id;
	cout<<"\n\n\tName of the teacher is :--- \t";
	cout<<name;
	cout<<"\n\n\tSUBJECT OF THE TEACHER :--- \t ";
	cout<<tchr_sub;
	cout<<"\n\n\tTotal number of free periods of the teacher in a week :---\t"<<no_fprd<<"\n\n\n\n";
	cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
	cout<<"\n    DAY\t      1st\t2nd\t3rd\t4th\t5th\t6th\t7th\t8th\n";
    cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n  MONDAY\t";
    for(int a=0;a<8;++a)
    {
        cout<<MO[a]<<"\t";
    }
    cout<<"\n\n  TUESDAY\t";
    for(int b=0;b<8;++b)
    {
        cout<<TU[b]<<"\t";
    }
     cout<<"\n\n  WEDNESDAY\t";
    for(int c=0;c<8;++c)
    {
        cout<<WE[c]<<"\t";
    }
    cout<<"\n\n  THURSDAY\t";
    for(int d=0;d<8;++d)
    {
        cout<<TH[d]<<"\t";
    }
     cout<<"\n\n  FRIDAY\t";
    for(int e=0;e<8;++e)
    {
        cout<<FR[e]<<"\t";
    }
    cout<<"\n\n  SATURDAY\t";
    for(int f=0;f<8;++f)
    {
        cout<<SA[f]<<"\t";
    }

}
void teacher::show_all()                                            //Process terminated with status -1073741510
{
    cout<<" "<<tchr_Id<<setw(20)<<" "<<name<<setw(10)<<" "<<tchr_sub<<setw(18)<<" "<<no_fprd<<endl;}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
void teacher::find_tchr()
{
    int dcode,prdno;
    cout<<"\n\n ENTER THE DAY CODE :---\t";
    cin>>dcode;cout<<"\n\n";
    cout<<" ENTER PERIOD NUMBER :---\t";
    cin>>prdno;cout<<"\n\n  ";
    switch(dcode)
    {
    case 1:
        cout<<"NOW "<<name<<" is in "<<MO[prdno-1];
        break;
    case 2:
        cout<<"NOW "<<name<<" is in "<<TU[prdno-1];
        break;
    case 3:
        cout<<"NOW "<<name<<" is in "<<WE[prdno-1];
        break;
    case 4:
        cout<<"NOW "<<name<<" is in "<<TH[prdno-1];
        break;
    case 5:
        cout<<"NOW "<<name<<" is in "<<FR[prdno-1];
        break;
    case 6:
        cout<<"NOW "<<name<<" is in "<<SA[prdno-1];
        break;
    default:
        cout<<"PLEASE ENTER A VALID DAY CODE.";
    }
}
int teacher::ret_tchrId() const
{
	return tchr_Id;
}

void create_tchr();
void modify_tchr(int);
void tchr_details(int);
void search_tchr(int);
void all_display();
void delete_tchr(int);
void intro();[\code]

void create_tchr();
void modify_tchr(int);
void tchr_details(int);
void search_tchr(int);
void all_display();
void delete_tchr(int);
void intro();

int main()
{
    int ch;
	int num;teacher tchr;
	intro();ostream os; 
        ofstream outfile;                                       // ......................TBD....................
	do
	{
		cout<<"\n\n\n\tMAIN MENU";
		cout<<"\n\n\t01. ADD A TEACHER";
		cout<<"\n\n\t02. UPDATE A TEACHER'S DETAILS";
		cout<<"\n\n\t03. FIND A TEACHER";
		cout<<"\n\n\t04. DISPLAY A TEACHER'S DETAILS";
		cout<<"\n\n\t05. LIST OF ALL TEACHERS";
		cout<<"\n\n\t06. REMOVE A TEACHER";
		cout<<"\n\n\t07. EXIT";
		cout<<"\n\n\tSelect Your Option (1-7) ";
		cin>>ch;
		switch(ch)
		{
		case 1:
		    outfile.open("teacher.dat",ios::out|ios::binary|ios::app);
			tchr.create_tchr(&os);
			break;
		case 2:
			cout<<"\n\n\tEnter The Teacher's ID : "; cin>>num;
			modify_tchr(num);
			break;
		case 3:
			cout<<"\n\n\tEnter The Teacher's ID : "; cin>>num;
			search_tchr(num);
			break;
		case 4:
			cout<<"\n\n\tEnter The Teacher's ID : "; cin>>num;
			tchr_details(num);
			break;
		case 5:
			 all_display();
			break;
		case 6:
			cout<<"\n\n\tEnter The Teacher's ID : "; cin>>num;
			delete_tchr(num);
			break;
        case 7:
			cout<<"\n\n\t BLA BLA BLA";                                              //KUCH LIKH DENA
			break;
		 default :cout<<"\a     INVALID CHOICE     \a";
		}
		cin.ignore();
		cin.get();
	}while(ch!=7);
	return 0;

}
/*void create_tchr()
{
    teacher tchr;
	ofstream outFile;
	outFile.open("Teacher.dat",ios::binary|ios::app);
	tchr.add_tchr();
	outFile.write(reinterpret_cast<char *> (&tchr), sizeof(teacher));
	outFile.close();
}*/

void modify_tchr(int n)
{
    bool found=false;
	teacher tchr;
	fstream File;
	File.open("Teacher.dat",ios::binary|ios::in|ios::out);
	if(!File)
	{
		cout<<"File could not be open !! Press any Key...";
		return;
	}
	while(!File.eof() && found==false)
	{
		File.read(reinterpret_cast<char *> (&tchr), sizeof(teacher));
		if(tchr.ret_tchrId()==n)
		{
			tchr.expand_tchr();
			cout<<"\n\nEnter The New Details of teacher"<<endl;
			tchr.update_tchr();
			int pos=(-1)*static_cast<int>(sizeof(teacher));
			File.seekp(pos,ios::cur);
			File.write(reinterpret_cast<char *> (&tchr), sizeof(teacher));
			cout<<"\n\n\t Details Updated";
			found=true;
		  }
	}
	File.close();
	if(found==false)
		cout<<"\n\n Teacher Not Found ";
}

void tchr_details(int n)
{
    teacher tchr;
	bool flag=false;
	ifstream inFile;
	inFile.open("Teacher.dat",ios::binary);
	if(!inFile)
	{
		cout<<"File could not be open !! Press any Key...";
		return;
	}
	cout<<"\nTEACHER DETAILS\n";

    	while(inFile.read(reinterpret_cast<char *> (&tchr), sizeof(teacher)))
	{
		if(tchr.ret_tchrId()==n)
		{
			tchr.expand_tchr();
			flag=true;
		}
	}
	inFile.close();
	if(flag==false)
		cout<<"\n\nTeacher ID does not exist";
}

void search_tchr(int n)
{
    teacher tchr;
	bool flag=false;
	ifstream inFile;
	inFile.open("Teacher.dat",ios::binary);
	if(!inFile)
	{
		cout<<"File could not be open !! Press any Key...";
		return;
	}
	  	while(inFile.read(reinterpret_cast<char *> (&tchr), sizeof(teacher)))
	{
		if(tchr.ret_tchrId()==n)
		{
			tchr.find_tchr();
			flag=true;
		}
	}
	inFile.close();
	if(flag==false)
		cout<<"\n\nTeacher ID does not exist";
}
void all_display()
{
    teacher tchr;
	ifstream inFile;
	inFile.open("Teacher.dat",ios::binary);
	if(!inFile)
	{
		cout<<"File could not be open !! Press any Key...";
		return;
	}
	cout<<"\n\n\t\tTEACHER'S LIST\n\n";
	cout<<"============================================================================\n";
	cout<<"Teacher-ID            NAME          SUBJECT         No. of free periods\n";
	cout<<"============================================================================\n";
	while(inFile.read(reinterpret_cast<char *> (&tchr), sizeof(teacher)))
	{
		tchr.show_all();
	}
	inFile.close();
}

void delete_tchr(int n)
{
    teacher tchr;
	ifstream inFile;
	ofstream outFile;
	inFile.open("Teacher.dat",ios::binary);
	if(!inFile)
	{
		cout<<"File could not be open !! Press any Key...";
		return;
	}
	outFile.open("Tmp.dat",ios::binary);
	inFile.seekg(0,ios::beg);
	while(inFile.read(reinterpret_cast<char *> (&tchr), sizeof(teacher)))
	{
		if(tchr.ret_tchrId()!=n)
		{
			outFile.write(reinterpret_cast<char *> (&tchr), sizeof(teacher));
		}
	}
	inFile.close();
	outFile.close();
	remove("Teacher.dat");
	rename("Tmp.dat","Teacher.dat");
	cout<<"\n\n\tRecord Deleted ..";
}

void intro()
{
    return;
}


as advised..i 've done the editing in lines 40-58 and 278,279.

GETTING ERROR ---- error: 'std::basic_ostream<_CharT, _Traits>::basic_ostream() [with _CharT = char; _Traits = std::char_traits<char>]' is protected


1
2
error: no matching function for call to 'teacher::create_tchr(std::ostream*)'
    tchr.create_tchr(&os);


note: no known conversion for argument 1 from 'std::ostream* {aka std::basic_ostream<char>*}' to 'std::ostream& {aka std::basic_ostream<char>&}'

1
2
 error: within this context
  int num;teacher tchr;ostream os;



PS : I AM A BEGINNER AND I USE CODEBLOCKS 13.12
Last edited on
Please use code tags :+)

http://www.cplusplus.com/articles/z13hAqkS/


You say you have no warnings, what compiler switches are you using? Just want to check, not doubting you :+) Sometimes people don't set their warning level high enough.

Consider using a debugger, if using an IDE, there should be a GUI one built in.

Good Luck!!
This for(int z=0;z<8;++z) is your problem: Your arrays can hold 7 items, but you enter 8.

In most (if not all) loops you use 8 instead of the correct 7. I suggest that you make a named constant and use that instead of those 'magic numbers'.
#theideasman , am a beginner and i dont know about compiler switches and also how to use the debugger.

#coder777 , THANKS A TON MAN....u suggestion helped a lot. IN line 11 , I changed the array sizes to 8 from 7 and now the add_tchr function works fine.

BUT the other functions (ie. expand_tchr,show_all,find_tchr) are crashing.i couldn't check these earlier as the add_tchr function wasn't working.Thanks 2 U , now its working fine. But other functions are not. PLZ SUGGEST what might be the errors and how i can rectify them.

now i get----Process terminated with status -1073741510
In find_tchr(): You need to check whether prdno is out of bounds. Furthermore it is rather prdno-1 because the user probably enters 1 where the index in your array is 0.

You cannot read/write the teacher data like this:

File.read(reinterpret_cast<char *> (&tchr), sizeof(teacher));

outFile.write(reinterpret_cast<char *> (&tchr), sizeof(teacher));

Pointers within string MO[7],TU[7],WE[7],TH[7],FR[7] are overwritten and the result is undefined behavior, most likely a crash.

Better use getline(...) and/or operator>> for reading and operator<< for writing (make sure that you have new line/whitespace between the entries).

I would suggest to create function in class teacher that processes the reading/writing for a single data record.
#theideasman , am a beginner and i dont know about compiler switches and also how to use the debugger.


Well, I think you are the stage already where you need to learn these things. Have a read of the help in you IDE.

If you click on the gear icon for the code you posted, you can set all the warnings there -Wall -Wextra and -pedantic. Set all those & run the code, errors etc will turn up in the compilation tab. These are options for the g++ compiler so you might need to look for similar things on your compiler.

Using a debugger is almost indispensable for runtime errors. It will save days of staring at code.

Good Luck!!
@theideasman , my compiler is mingw32-g++ ,and i found the -Wextra option in the compiler settings. but i still dont understand how to use the debugger.
Just a note: don't use gets. It is unsafe (and was removed in the C++11 standard.)

See: http://stackoverflow.com/a/4346934
@theideasman , my compiler is mingw32-g++ ,and i found the -Wextra option in the compiler settings. but i still dont understand how to use the debugger.


Ah good, your compiler is a variant of g++. If you found -Wextra , you can do -pedantic as well.

So with CodeBlocks, I have v12.11 there is a debug menu.

Select the debugging windows, make sure the watch window is on.

In the watch window, type in the names of some variables you want to keep an eye on.

Place the cursor in the code, just before you think there might be a problem

On the debug menu, select "run to cursor"

Look at the values of the variables as you step through the code line by line, deduce where things went wrong.

Hope all goes well :+)
Reading/Writing data using the stream operators is relatively simply:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class teacher
{
    int tchr_Id,no_fprd;
    char name[30],tchr_sub[15];
    string MO[7],TU[7],WE[7],TH[7],FR[7];
public:
...
    read_data(istream &is)
    {
        is >> tchr_Id >> no_fprd >> ws; // Note: ws to remove the end of line character '\n'
        is.getline(name, sizeof(name)); // Same for tchr_sub
...
        for(int z=0;z<8;++z)
        {
          getline(MO[z]);
          getline(TU[z]);
...
        }
    }
...
    write_data(ostream &os)
    {
        os << tchr_Id << ' ' << no_fprd << endl;
        os << name << endl;
...
        for(int z=0;z<8;++z)
        {
          os << MO[z] << endl;
          os << TU[z]  << endl;
...
        }
    }
};
...
// Read example:
// Note: You need a containe/array for multiple teacher data
{
  for(teacher_count = 0; (teacher_count < max_teacher_count) && inFile; ++teacher_count)
  {
    teacher_container[teacher_count].read_data(inFile);
  }
}
Note: not tested.

Ask if something is unclear.
Last edited on
@coder777 error: ISO C++ forbids declaration of 'create_tchr' with no type [-fpermissive]

i named the read_data() as create_tchr. What shout be the type of read_data(istream &is) and write_data(ostream &os) functions ?

AND plz explain the note.
error: ISO C++ forbids declaration of 'create_tchr' with no type [-fpermissive]
You need to add the return type. Since those functions don't return anything, the return type should be void.
@cire thanks ..but i tried that and still getting errors.

i've posted the edited code after changing my write function. line 107-115 (inside comment lines) shows my old write function which did not show any errors but problems occured during runtime. line 39-57 show my new write function which i made ap per the advice of #coder777 and i hv given a list of errors am getting at the end of my program. PLZ help me.
The examples I gave you where no where complete. You have do add the missing things yourself.

You get the errror because (on line 75) you pass the stream as a pointer, but you need to pass it by reference:

tchr.create_tchr(&os); // Note: remove the &

AND plz explain the note.
What is unclear about the notes?
error: 'std::basic_ostream<_CharT, _Traits>::basic_ostream() [with _CharT = char; _Traits = std::char_traits<char>]' is protected

1
2
error: within this context
  int num;teacher tchr;ostream os;


STill showing these errors.(after removing &).....and why does the program crash ?
Remove ostream os; use outfile instead.

It will still crash until you have those wrong file reads everywhere in your program.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 bool found=false;
	teacher tchr;
	fstream File;
	File.open("Teacher.dat",ios::binary|ios::in|ios::out);
	if(!File)
	{
		cout<<"File could not be open !! Press any Key...";
		return;
	}
	while(!File.eof() && found==false)
	{
		File>> tchr_Id >> no_fprd >> ws;
        File.getline(name, sizeof(name));
        File.getline(tchr_sub, sizeof(tchr_sub));
        istream is;
        for(int z=0;z<8;++z)
        {
          is.getline(MO[z]);
          is.getline(TU[z]);
          is.getline(WE[z]);
          is.getline(TH[z]);
          is.getline(FR[z]);
          is.getline(SA[z]);
        }


wat is the error in this ???? its showing

error: 'std::basic_istream<_CharT, _Traits>::basic_istream() [with _CharT = char; _Traits = std::char_traits<char>]' is protected

error: no matching function for call to 'std::basic_istream<char>::getline(std::string&)'

same errors persist even if i use ifstream.

{
for(teacher_count = 0; (teacher_count < max_teacher_count) && inFile; ++teacher_count)
{
teacher_container[teacher_count].read_data(inFile);
}
}



how will i get max_teacher_count ? and how to declare teacher_container ?
Last edited on
Just my 2 cents worth :+)

Don't loop on eof , loop on the stream itself.
You used getline wrongfully. Read for std::string:

http://www.cplusplus.com/reference/string/string/getline/?kw=getline



For c-string you use the other getline:

http://www.cplusplus.com/reference/istream/istream/getline/



Remove line 15. Line 18 to 23: getline(File, ...);
Topic archived. No new replies allowed.