头文件:
#ifndef STUDENT_H_
#define STUDENT_H_
#include <string>
using namespace std;
class Student {
public:
Student();
Student(string, char, string, int);
void setFirstName(string);
void setMiddleName(char);
void setLastName(string);
void setScore(int);
string getFirstName();
char getMiddleName();
string getLastName();
int getScore();
private:
string firstName;
char middleName;
string lastName;
int score;
};
Student::Student() {
}
Student::Student(string firstName, char middleName, string lastName, int score) {
setFirstName(firstName);
setMiddleName(middleName);
setLastName(lastName);
setScore(score);
}
void Student::setFirstName(string firstName) {
this->firstName = firstName;
}
void Student::setMiddleName(char middleName) {
this->middleName = middleName;
}
void Student::setLastName(string lastName) {
this->lastName = lastName;
}
void Student::setScore(int score) {
this->score = score;
}
string Student::getFirstName() {
return firstName;
}
char Student::getMiddleName() {
return middleName;
}
string Student::getLastName() {
return lastName;
}
int Student::getScore() {
return score;
}
#endif /* STUDENT_H_ */
测试类:
#include <iostream>
#include <fstream>
#include "Student.h"
using namespace std;
void displayStudent(Student stu);
int main() {
Student stu1("John", 'T', "Smith", 90);
Student stu2("Eric", 'K', "Jones", 80);
displayStudent(stu1);
displayStudent(stu2);
fstream binaryio;
binaryio.open("stu.dat", ios::out | ios::binary);
binaryio.write(reinterpret_cast<char*> (&stu1), sizeof(stu1));
binaryio.write(reinterpret_cast<char*> (&stu2), sizeof(stu2));
binaryio.close();
cout << "--------------------" << endl;
Student stu;
binaryio.open("stu.dat", ios::in | ios::binary);
binaryio.read(reinterpret_cast<char*> (&stu), sizeof(stu));
displayStudent(stu);
binaryio.read(reinterpret_cast<char*> (&stu), sizeof(stu));
displayStudent(stu);
binaryio.close();
}
void displayStudent(Student stu) {
cout << stu.getFirstName() << " " << stu.getMiddleName() << " " << stu.getLastName() << " " << stu.getScore() << endl;
}
分享到:
相关推荐
C#删除文件到回收站DEMO源码 原理:调用Microsoft.VisualBasic.FileIO功能删除文件、文件夹到回收站。实测通过。DEMO为控制台程序,可方便地将代码移植到您的项目中。
文件输入输出,写的一个例子,关于streamread,streamwrite的使用。
fileio is the verilog file
file input and output
fileIO_sample.c_fileIO_源码.zip
一个dir中较好使用的文件读取和写入的插件,里面包含了基本的使用实例说明,下载后直接添加即可使用。网络上已经很难再下到了
FileIO.jar
MATLAB MAT File IO Library
SQL Tuning - File IO Performance
C# File 类 (System_IO)
Qt6 QML Book/扩展QML/使用FileIO 示例源码 CSDN审核可能较慢,如无法下载,可以过段时间再回来看下 仅供相关爱好者交流使用,请于下载24小时内删除
Qt6 QML Book/扩展QML/FileIO实现 示例源码 CSDN审核可能较慢,如无法下载,可以过段时间再回来看下 仅供相关爱好者交流使用,请于下载24小时内删除
file.io实用程序在您的终端上使用临时文件共享服务!... 基本上,唯一的可选参数是有效期限,例如./fileio -e 1m somefile.png例子输入: ./fileio somefile.png输出: Uploading to file.io...Link:
1、资源内容:基于 Microsoft.VisualBasic.FileIO.TextFieldParser 的简单 CSV 分析器 2、适用人群:计算机,电子信息工程、数学等专业的学习者,作为java实战项目,课程设计,毕业设计“参考资料”参考学习使用。 3...
资源分类:Python库 所属语言:Python 资源全名:exoedge_fileio-20.8.3-py2.py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
android 下的文件读写操作源码,可供入门学习
Linux c 文件io 读写源码 全集
自己用java编写的文件读写,包括字节流、字符流、缓冲字节流、缓冲字符流的读入和写出,jar包下载好可以在编译器里导入,也可以在cmd里输入java -jar 。并将jar包拖入。注:java和-jar间有空格,-jar之后再打一个...
是一个记事本,很好用。没有用任何的辅助图形编辑工具。