c++文件按行拆分

void splitFile()
{
	int filelinenum=FILELINE/MAX;
	ifstream ifs("./test.txt");
	string str;
	int num=1;
	int i=1;
	for(i=1;i<=MAX;i++)
	{
		strstream aa;
		aa<<(i-1);
		string strCount;
		aa>>strCount;
		string filepath = "./test"+strCount+".txt";
		ofstream ofs(filepath.c_str());
		int start = filelinenum*(i-1)+1;
		int end = filelinenum*i;
		while((num!=(end+1))&&getline(ifs,str))
		{
			if(num>=start && num <=end){
				ofs<<str<<endl;
				num++;
			}
			else{
				num++;
				break;
			}
		}
	}
}
 

你可能感兴趣的:(C++)