c++对文件操作的支持(二)
#include <stdio.h>
#include <iostream>
#include <fstream>
using namespace std;
void main()
{
int a,b;
char c;
ofstream fout("test.txt");
fout<<<<" "<<<<" "<<<<endl;
fout<<<<" "<<<<" "<<'d'<<endl;
ifstream fin("test.txt");
while (!fin.eof())
{
fin>>a>>b>>c;
if(fin.fail()) continue; //忽略文件中的空行
cout<<a<<" "<<b<<" "<<c<<endl;
}
cin>>a;
}
http://www.cplusplus.com/doc/tutorial/files/">http://www.cplusplus.com/doc/tutorial/files/
2.
#include <iostream>
#include <fstream>
using namespace std; char *getmemory ()
{
char *p = (char *)malloc(*sizeof(char));
return p;
} void getmemory2(char**p)
{
*p = (char *)malloc(*sizeof(char));
} int main()
{
static int num =;
char *str = NULL;
//知识点1___给str分配内存的几种方法
//str= getmemory();
//getmemory2(&str);
//str = (char*)malloc(100*sizeof(char));
str = (char *) calloc(100,sizeof(char)); //区别与malloc: calloc在动态分配完内存后,自动初始化该内存空间为零,而malloc不初始化,里边数据是随机的垃圾数据
//str = new char[];
memset(str,,); // 初始化 ; 赋值语句 = strcpy(str,"sadfsa"); double a = 0.0;
int b = ;
char c='a';
ifstream fin("data.txt");
while (!fin.eof())
{
fin.getline(str,);
if (strlen(str) ==) continue; //知识点2___对文件中出现空行的处理
sscanf(str,"%lf,%d,%c",&a , &b ,&c); //知识点3___将读取的字符串转换为相应的数据类型
num++;
if (num ==)
cout<<"data.txt中的数据如下"<<endl;
cout<<a<<","<<b<<","<<c<<endl;
}
free(str);
cout<<"文件共有"<<num<<"数据"<<endl;
return ;
}
更多参考: http://www.jizhuomi.com/software/340.html
c++对文件操作的支持(二)的更多相关文章
- 总结文件操作函数(二)-C语言
格式化读写: #include <stdio.h> int printf(const char *format, ...); //相当于fprintf( ...
- vc文件操作汇总—支持wince
一.判断文件及文件夹是否存在 // 判断文件是否存在 BOOL IsFileExist(const CString& csFile) { DWORD dwAttrib = GetFileAtt ...
- 【转】c#文件操作大全(二)
61.文件夹移动到整合操作 FolderDialog aa = new FolderDialog(); aa.DisplayDialog(); if (aa ...
- c++对文件操作的支持(一)
#include <stdio.h> #include <iostream> #include <fstream> using namespace std; voi ...
- 文件操作(十二)——open,read,close,write,seek,truncate
open函数 #!/usr/bin/env python #-*- coding:utf8 -*- f = open('xxx','r',encoding='utf-8') data = f.read ...
- Java中常用到的文件操作那些事(二)——使用POI解析Excel的两种常用方式对比
最近生产环境有个老项目一直内存报警,不时的还出现内存泄漏,导致需要重启服务器,已经严重影响正常服务了.获取生成dump文件后,使用MAT工具进行分析,发现是其中有个Excel文件上传功能时,经常会导致 ...
- File API文件操作之FileReader二
上一篇说了FileAPI中FileReader的readAsText,这里继续上文,说说另外一个API readAsDataURL. 这个接口是将File或者Blob读成base64格式的字符串,然后 ...
- HTML5 本地文件操作之FileSystemAPI实例(二)
文件操作实例整理二 1.删除文件.复制文件.移动文件 //获取请求权限 window.requestFileSystem = window.requestFileSystem || window.we ...
- 4 文件操作 支持图片 视频 mp3 文本等
#文件操作:send_file,支持图片 视频 mp3 文本等@app.route("/img")def img(): return send_file("1.jpg&q ...
随机推荐
- Email Cover Letter Format
http://jobsearch.about.com/od/sampleletters/ig/Sample-Letter-Formats/Email-Message-Format.htm Copy ...
- MVC不错的学习资料
MVC不错的学习资料: http://www.cnblogs.com/darrenji/
- RTUILabel+正则表达式
RTLabel和RegexKitLite都要导入第三方库 使用Regexkitlite库进行正则表达式的解析 1.库是使用MRR,如果在ARC工程里面使用这个类,必须在project->buil ...
- DataGridView显示行号
//可以在DataGirdView的RowPostPaint事件中进行绘制. //如:添加以下方法代码 private void DrawRowIndex(object sender, DataGri ...
- WindowsForm 流
流 包括输入流代码 输出流代码 流: 输入流: string filename = openFileDialog1.FileName; //通过读入流进行文件读取 StreamReader sr = ...
- Windows上Python3.5安装Scrapy(lxml)
常用网址: Python 3.5: https://www.python.org/downloads/ Wheel文件:http://www.lfd.uci.edu/~gohlke/pythonlib ...
- SQL Server数据库空间管理 (1)
数据库经常遇到的问题: 1).数据库文件空间用尽 2).日志文件不停增长 3).数据库文件无法收缩 4).自动增长和自动收缩 本系列就以上面的4个问题入手分析并总结数据库空间的管理方法. 1. ...
- 使用LINQ来简化编程的7个技巧
转载地址:http://www.cnblogs.com/lovecherry/archive/2008/05/23/1205565.html 自从学习LINQ以来,我发现了很多使用LINQ来改善代码的 ...
- 从一个Bug说开去--解决问题的思路,Linked Server, Bulk Insert, DataTable 作为参数传递
声名— 部分内容为杜撰,如有雷同,不胜荣幸! 版权所有,如要引用,请标明出处! 如果打赏,请自便! 1 背景介绍 最近一周在忙一个SQL Server 的Bug,一个简单的Bug,更新两张 ...
- 如何测试私有 Private/Internal 方法
在实际开发中,经常会遇到这样的情况. 一个共有的 Public 方法实现某一主要功能,但是由于该功能的实现非常复杂,需要很多的辅助类,辅助方法.由于代码封装性的需求,我们通常需要把这些辅助的类方法定义 ...