在VC ^中更改txt文件的名称 [英] Changing a name of a txt file in VC^
本文介绍了在VC ^中更改txt文件的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好我有以下代码
Hi I have the following code
CString str1;
CFileDialog FileDlg1(FALSE," ","ch1",OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT , "TXT File(*.txt)|*.txt|All(*.*)|*.*|");
if(FileDlg1.DoModal()==IDOK)
{
ofstream ofs(FileDlg1.GetPathName());
ofs.write(str1,str1.GetLength());
ofs.close();
AfxMessageBox("CH1 Data Saved!");
}
ofstream Data_ch1("ch1.txt", ios::out);
简单地说,它将Data_ch1的数据保存在txt文件中。问题是它使用名称ch1.txt保存数据,如果更改此名称,则文件中将丢失数据。我需要一种方法来更改文件的名称,以便更改内的名称取决于用户。
我尝试了什么:
我试图使用GetWindowText和SetWindowText,但是它们没有用。
what it simply does, it saves the data of Data_ch1 in a txt file. the problem is that it saves the data with the name ch1.txt and if this name is changed the data will be missed in the file. i need a method to change the name of the file so the name inside " " is changed depends on the users.
What I have tried:
I tried to use GetWindowText and SetWindowText but they did not work.
推荐答案
而不是使用硬编码值ch1.txt,使用FileDlg1.GetPathName()
。这将返回用户选择的文件的名称。
/ ravi
Instead of using the hard coded value "ch1.txt", useFileDlg1.GetPathName()
. That returns the name of the file selected by the user.
/ravi
这篇关于在VC ^中更改txt文件的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文