blob: d58d6dfd8c5e9b5361a3c53d113a2c89df1ea666 (
plain)
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
|
// Student.cpp: Implementation of class Student.
#include <iostream>
using std::cout;
using std::endl;
using std::istream;
using std::ostream;
#include <string>
using std::string;
using std::getline;
#include "Student.h"
Student::Student()
{
}
Student::~Student()
{
}
void Student::set( string n, int m, int a )
{
name = n;
matNr = m;
age = a;
}
void Student::print()
{
cout << name << ", Matrikelnummer: " << matNr << ", Alter: " << age << endl;
}
ostream& Student::write( std::ostream& os ) const
{
// os.write( ( char* )&matNr, sizeof matNr ); // stores '578111' as an int in 4 Bytes
// os << matNr; // stores '578111' as ASCII-Code in 6 Bytes!
os << name << '\0'; // write string
os.write( ( char* ) &matNr, 2 * sizeof( int ) ); // write 2 int starting at address of matNr
return os;
}
istream& Student::read( std::istream& is )
{
getline( is, name, '\0' ); // read string
is.read( ( char* ) &matNr, 2 * sizeof( int ) ); // read 2 int starting at address of matNr
return is;
}
|