C++实现读取文件的指定行数的方法

相关的理论基础,可以参考这个博客的内容:

https://www.cnblogs.com/fnlingnzb-learner/p/5833051.html

#include 
#include 
#include 

using namespace std;
using std::map;
map gMapStep;

int i = 0;
bool isExitsts = -1;
int fileTotalLineNum = 0;
int val = -1;
std::string line;

static int readFileByLineNum(uint32_t LineNum, char *Cont[512])
{
	isExitsts = access(FILE_NAME_PATH, F_OK);
	if(!isExitsts)
	{
		ifstream infile(FILE_NAME_PATH);
		val = 0;
		while(std::getline(infile, line))
		{
			gMapStep[val++] = line;
		}   
		fileTotalLineNum = val;
		LOG("fileTotalLineNum:[%d]  val [%d] \n",fileTotalLineNum, val);
		infile.close();
	}
	strncpy(Cont, gMapStep[danceId+3].c_str(), strlen(gMapStep[danceId+3].c_str()));
	
	return 0;
}

 

你可能感兴趣的:(c++面试,linux系统编程,c,读取文件的指定行的内容)