读文件操作
来源:互联网 发布:python使用指南 编辑:程序博客网 时间:2024/05/29 12:29
// 读文件.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <string.h>
#include <stdio.h>
#include <fstream.h>
// 去除字符串头部的空白,只是改变指针位置,不做数据移动操作,例如" 111"-> "111"
void RemoveHeadSpaceFromString(const char **ppStr)
{
if((NULL == ppStr) || (NULL == *ppStr))
{
return;
}
const char *p = *ppStr;
while((' ' == *p) || ('\t' == *p) || ('\r' == *p))
{
p++;
}
*ppStr = p;
}
int ReadFileTest(ifstream &ifs)
{
char strLine[512]={0};
int iCount=0;
// 参数检查
if(!ifs.is_open() || !ifs.good())
{
return -1;
}
streampos pos = ifs.tellg(); // 当前文件指针位置
// 逐行读取并判断
while (ifs.good())
{
// 首先保存文件指针,用于读取到不该本函数判断处理的行时回退
pos = ifs.tellg();
//cout<<pos<<endl;
// 读取一行
memset(strLine, 0, sizeof(strLine));
ifs.getline(strLine, sizeof(strLine));
// 去除头部的空白
const char *pLine = strLine;
RemoveHeadSpaceFromString(&pLine);
cout<<pLine<<endl;
if(strcmp(strLine, "333")==0 && iCount<3)
{
// 文件指针回退
ifs.seekg(pos);
++iCount;
}
}
}
int main(int argc, char* argv[])
{
ifstream ifs("f://aa.txt");
LoadParamItems(ifs);
return 0;
}
- 文件操作 读文件
- Delphi文件操作-读文件-写文件-操作文件
- JAVA 读文件操作
- 读文件操作
- 文件的读操作
- java文件读操作
- lua读文件操作
- C#读文件操作
- 文件对象-读操作
- c++ 读文件操作
- 文件读操作
- 使用rapidxml操作xml2(读文件操作)
- 使用RAPIDXML操作XML2(读文件操作)
- matlab文件操作及读txt文件
- matlab文件操作及读txt文件
- matlab文件操作及读txt文件
- matlab文件操作及读txt文件
- Java读文件写文件操作
- 最小化当前应用程序
- jni获取mac地址的问题  -  棒槌网@Android开发论坛 - Powered by phpwind
- Container
- 源码网站推荐
- Barcode条形码及对图片进行270翻转
- 读文件操作
- 微软控件telerik report中怎样设置分页
- UVa 111 - History Grading
- log4j用法心得:
- Android-网络交互之客户端请求服务端资源-stoneson的专栏-  -  棒槌网@Android开发论坛 - Powered by phpwind
- Daniel Robbins sed 实例 POSIX 线程详解
- jvm terminated exit code =-1
- 数据挖掘所用到的一些数据集资源
- 短信的虚拟键盘不见了