file read & write

1.数据流创建文件.txt

#include <iostream>

.........

#define numberImg  112   //picture number
#define nArray     8     //cols
string filePath = ".\\1"; //the picture in file path
string imgType = ".bmp"; //picture type

int _tmain(int argc, _TCHAR* argv[])
{
	ofstream pathTxt;
	pathTxt.open("1.txt", std::ios::out | std::ios::app);
	if(!pathTxt.is_open())
		return 0;
	string fileBuffer;
	for(int i = 0; i < numberImg; i++)
	{
		string imgNameRef = "\\0_" + imgType;
		
		//int convert to string
		stringstream ss;
		ss<<i;
		string str = ss.str();
		string imgName= imgNameRef.insert(3, str);
        
		//merage string for get picture path
		fileBuffer = filePath + imgName;
		pathTxt<< fileBuffer << endl;
		
		cout<<"fileBuffer = "<<fileBuffer<<endl;
	}
	pathTxt.close();
	return 0;
}

目的:获取图片的命名,进行读取并合并

************************************************************************

2.数据流读取按行.txt内容

#define numberImg  112   //picture number

int _tmain(int argc, _TCHAR* argv[])
{
	string file= "1.txt";
	ifstream pathTxt;
	pathTxt.open(file.data());
	assert(pathTxt.is_open());
    

	string s;
	for(int i = 0; i < numberImg; i ++)
	{
		getline(pathTxt, s);
		cout<<s<<endl;
	}
    pathTxt.close();

	return 0;
}

目的:获取txt中的内容,进行命名获得

***************************************************

void CfolderDlg::OnBnClickedButton()
{
    CString folderName;
	GetDlgItem(IDC_EDIT)->GetWindowText(folderName);
	CString path = "d:\\" + folderName;  
	if (!PathIsDirectory(path))  
		::CreateDirectory(path, 0);  
}
MFC创建文件夹

猜你喜欢

转载自blog.csdn.net/zxl2712028/article/details/80266921