overload operator >>

Hi every.
My code get a run-time error and I can't understand what it is. can anyone help me.
This is header file.
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
#ifndef MANAGEMENT_DATA_H
#define MANAGEMENT_DATA_H
#include<iostream>
using namespace std;
namespace Students{
	class Student{
	private:
		string family_name;
		string last_name;
		int age;
	public:
		Student(string a=0, string b=0, int c=0): family_name(a), last_name(b), age(c){}
		~Student(){}
		friend istream& operator>>(istream&, Student&);
	};
istream& operator>>(istream& is, Student& a){
	cout<<"enter the family name: ";
	cin>>a.family_name;
	cout<<"enter the last name: ";
	cin>>a.last_name;
	cout<<"enter the age: ";
	cin>>a.age;
	return is;
}
}
#endif 

and main:
1
2
3
4
5
6
7
8
9
10
11
12
13
#include<iostream>
#include<string>
#include<Windows.h>
#include"Students.h"
#include"Grade.h"
using namespace std;
int main()
{
	Students::Student a;
	cin>>a;
	system("pause");
	return 0;
}

when run, it get a "MICROSOFT VISUAL C++ RUN-TIME LIBRARY"
Last edited on
have you tried to move the definition of operator>>() outside of namespace Students?
Or add using namespace Students; in main file?
Last edited on
I think that problem is in "#include<string>". but I can't repair it and understand what problem is?
I had solved it. I insert all "0" in default constructor of all string by a null string.
 
Student(string a="", string b="", int c=0):family_name(a), last_name(b), age(c){}

I had tried insert "0" by NULL. But it didn't compile. I have a question, I must build default constructor with a plain string???
Last edited on
NULL is not a string, it is a pointer. If you want an empty string, you have to specify it yourself. You can't have a "not yet constructed" string if that's what you were trying to do.
yes. thank you very much :)
Topic archived. No new replies allowed.