您的位置:首页 > 其它

读取文件每一行

2009-06-02 00:01 120 查看
#include <string>
#include <iostream>
#include <fstream>
#include <algorithm>

void main()
{
FILE *fp;
int count=0;
const int ARRAY_SIZE = 256;
char buff[ARRAY_SIZE];
int *location;

fp=fopen("1.txt","r");

std::string strWholeLine = "";

bool bNotEnd = false;

while(fgets(buff, ARRAY_SIZE, fp) != NULL)
{
std::string strc = buff;

size_t stIndex = strc.find("/n");
if (feof(fp))
{
++count;
std::cout << count << ": " << strc /*<< std::endl*/;
}
else if (stIndex != std::string::npos)
{
++count;

if (!bNotEnd)
{
std::cout << count << ": " << strc /*<< std::endl*/;
}
else
{
strWholeLine += buff;

std::cout << count << ": " << strWholeLine /*<< std::endl*/;

bNotEnd = false;

strWholeLine = "";
}
}
else
{
bNotEnd = true;

strWholeLine += buff;
}
}

fclose(fp);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: