C++读取文本的指定行

string ReadText(string filename, int line)
{
	ifstream fin;
	fin.open(filename, ios::in);
	string strVec[11];     //文本中总共有10行
	int i = 0;
	while (!fin.eof())
	{
		string inbuf;
		getline(fin, inbuf, '\n');
		strVec[i] = inbuf;
		i = i + 1;
	}
	return strVec[line - 1];
}


用此函数实现程序顺序读取文本中的图片路径
string filename;
	filename = ReadText("F:\\学习\\吉纳尔\\吉纳尔软件待完善版本\\测试图片\\calibdata.txt", ShowNum);  //ShowNum为要显示的行数
IplImage *image = NULL;
		if (image)
			cvReleaseImage(&image);
image = cvLoadImage(filename.c_str(), 0);


猜你喜欢

转载自blog.csdn.net/weixin_40113118/article/details/80282413