C++文件操作写入和读取结构体类型

// file2.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include 
#include 
using namespace std;
struct Student{
    int num;
    char name[20];
    };
int addInFile()
    {
    ofstream outFile("botao.dat",ios::out|ios::binary);  //定义文件输出流   文件不存在时创建文件
    //对文件打开错误时的操作
    if(!outFile)
        {
        cout<<"The file open error!"<>s->num;
        cout<<"输入学生姓名:";
        cin>>s->name;
        outFile.write((char*)s,sizeof(Student));   //文件输出流向文件中写入student信息
        }
    outFile.close();   //关闭输出流
    return 1;
    }
int myReadFile()
    {
    ifstream inFile("botao.dat",ios::in|ios::binary);   //文件输入流  将文件中的student信息读出到屏幕上
    //对文件打开错误时的操作
    if(!inFile)
        {
        cout<<"The inFile open error!"<num<name<            
            
                        
网站栏目:C++文件操作写入和读取结构体类型
文章位置:http://hxwzsj.com/article/igjcce.html

其他资讯

Copyright © 2025 青羊区翔捷宏鑫字牌设计制作工作室(个体工商户) All Rights Reserved 蜀ICP备2025123194号-14
友情链接: 营销网站建设 重庆外贸网站建设 品牌网站建设 成都网站建设公司 高端网站设计 成都网站建设 网站制作公司 成都网站建设 成都网站建设 网站建设方案 营销型网站建设 营销型网站建设 外贸网站设计方案 成都网站制作 企业网站设计 成都网站设计 商城网站建设 网站制作 网站建设公司 达州网站设计 移动手机网站制作 成都响应式网站建设