`
andy136566
  • 浏览: 285189 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

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;
			}
		}
	}
}
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics