首页 > 其他分享 >cpp: read .dat file

cpp: read .dat file

时间:2023-10-02 11:33:32浏览次数:33  
标签:char cout read dat outfile file cpp data

 

/// <summary>
/// 打开DAT 文件
/// </summary>
void operatefile()
{
	char data[100];
	const char* fname = "afile.dat";
	// 打开文件.
	ofstream outfile;
	outfile.open(fname,ios::in);
	if (!outfile)
	{
		cout << "文件不存在!" << endl;
		ofstream fout(fname); //创建文件
	}

	cout << "写文件" << endl;
	cout << "输入姓名: ";
	cin.getline(data, 100);

	// 写入.
	outfile << data << endl;

	cout << "输入年龄: ";
	cin >> data;
	cin.ignore();

	// 写入.
	outfile << data << endl;

	// 关闭文件.
	outfile.close();

	// 打开文件.
	ifstream infile;
	infile.open("afile.dat");

	cout << "读文件内容:" << endl;
	infile >> data;

	// 
	cout << data << endl;

	// 
	infile >> data;
	cout << data << endl;

	// 关闭文件
	infile.close();
}

  

标签:char,cout,read,dat,outfile,file,cpp,data
From: https://www.cnblogs.com/geovindu/p/17739804.html

相关文章

  • adoc转换html+UPF低功耗仿真例子+python转换C代码+readmemh的@使用
    adoc转换htmladoc这种格式是很多riscv文档使用的格式,该格式可以生成pdf,生成html。生成html的好处是,选中和翻译方便,复制粘贴方便。首先是gem软件要安装,这个软件似乎是ruby相关的(RubyGemsisapackagemanagerfortheRubyprogramminglanguagethatprovidesastandardform......
  • pthread实现多线程矩阵乘法
    #include<pthread.h>#include<stdio.h>#include<windows.h>#include<iostream>usingnamespacestd;#pragmacomment(lib,"pthreadVC2.lib")#definerowCount1300#definemediumCount1500#definecolumnCount5000#definen_threa......
  • Can't delete myfile.mexw64 after run mexw64?
    Ifoundmyanswer,this".mexw64"cannotbedeletedafterusingclear,butcanbedeletedafterusingclearallfromhttps://www.mathworks.com/matlabcentral/answers/1563471-can-t-delete-myfile-mexw64-after-run-mexw64......
  • The name org.freedesktop.secrets was not provided by any .service files 报错问
    在搭建cicddocker靶场的时候出现这个问题,由于是第一次遇到,就想记录下来 通过各种搜索资料搜索发现只要安装如下包就没问题 1apt-yinstallgnome-keyring 这样做之后,一切都可以这样就可以了 ......
  • redis 连接报错read error on connection解决
    在使用redis队列处理的时候,有时候队列过长会遇到超时的情况。原因分析:查看了下php.ini文件里面有个参数default_socket_timeout=60,就是这个配置导致redis过60秒会自动断开。这个配置是什么意思?default_socket_timeout是socket流的超时参数,即socket流从建立到传输再到关闭整个过......
  • jenkins教程:解决nodejs前端构建时报错(EMFILE: too many open files)
    修改系统最大打开文件数临时生效ulimit-n65535永久生效vim/etc/security/limits.conf*softnofile65535*hardnofile65535#修改单个进程最大打开文件数*softnprocunlimited*hardnprocunlimited查看修改结果ulimit-n配置完成后,restartjenkins即可生效。或者临时......
  • NO.4 Makefile文件制作
    一、Makefile定义变量(1)用户自定义变量变量定义直接用=使用变量值用$(变量名)如:下面是变量的定义和使用foo=abc//定义变量并赋值bar=$(foo)//使用变量,$(变量名)(2)Makefile自带变量CC=gcc#arm-linux-gccCPPFLAGS:C预处理的选......
  • Go每日一库之176:filetype(文件类型鉴别)
    filetype(https://github.com/h2non/filetype)是一个Go语言的第三方库,可以根据文件的魔数(magicnumbers)签名来推断文件的类型和MIME类型。它支持多种常见的文件类型,包括图片、视频、音频、文档、压缩包等。它还提供了一些便捷的函数和类型匹配器,可以方便地对文件进行分类和筛选......
  • 【代码片段】makefile 中通过 shell 函数执行 sed
    作者:张富春(ahfuzhang),转载时请注明作者和引用链接,谢谢!cnblogs博客zhihuGithub公众号:一本正经的瞎扯先上代码:(在macos上调试通过)#defineashellfunctiontosetdebugmodetoreleasemode#whenosismacbook,usegsedasseddefinefunction_sed_set_rel......
  • Go - Logging to File
    Problem: Youwanttologeventstoalogfileinsteadofstandarderror.Solution: UsetheSetOutputfunctiontosetthelogtowritetoafile. YouuseSetOutputtoredirecttheoutputtoafile.file,err:=os.OpenFile("app.log"......