How to read data from text file using CMFCEditBrowseCtrl vc++
-
Hello everyone! I am trying to use a CMFCEditBrowseCtrl button (in CFeaturesDialog class) to read numbers (integer) from a text file and then pass those numbers in separate text files (in CDataDialog class), each file for every number. So I wrote:
void CFeaturesDialog::OnEnChangeMfceditbrowse1()
{
CString str;
m_browser.GetWindowTextW(str); //CMFCEditBrowseCtrl m_browser;}
void CDataDialog::OnBnClickedOk()
{
CStdioFile file(L"over1.txt", CFile::modeCreate |
CFile::modeWrite);
}e.g. if there 2 numbers in text file I open with CMFCEditBrowseCtrl I want to create over1.txt which will include the first number and over2.txt which will include the second number. How could I do that? Thank you in advance!
-
Hello everyone! I am trying to use a CMFCEditBrowseCtrl button (in CFeaturesDialog class) to read numbers (integer) from a text file and then pass those numbers in separate text files (in CDataDialog class), each file for every number. So I wrote:
void CFeaturesDialog::OnEnChangeMfceditbrowse1()
{
CString str;
m_browser.GetWindowTextW(str); //CMFCEditBrowseCtrl m_browser;}
void CDataDialog::OnBnClickedOk()
{
CStdioFile file(L"over1.txt", CFile::modeCreate |
CFile::modeWrite);
}e.g. if there 2 numbers in text file I open with CMFCEditBrowseCtrl I want to create over1.txt which will include the first number and over2.txt which will include the second number. How could I do that? Thank you in advance!
lolici wrote:
I am trying to use a CMFCEditBrowseCtrl button (in CFeaturesDialog class) to read numbers... e.g. if there 2 numbers in text file I open with CMFCEditBrowseCtrl...
The
CMFCEditBrowseCtrl
class does not open files. That class is simply an editable text box that optionally contains a browse button. Are the numbers in the source file (comma) delimited, or one per line? Since I do not know the answer to either of this, I will error on the side of the latter, something like:CStdioFile fileSource("source.txt", CFile::modeRead);
CStdioFile fileDest;
CString strLine;
CString strFile;
int num = 1;while (file.ReadString(strLine))
{
strFile.Format("over%d.txt", num++);
fileDest.Open(strFile, CFile::modeWrite);
fileDest.WriteString(strLine);
fileDest.Close();
}fileSource.Close();
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
Hello everyone! I am trying to use a CMFCEditBrowseCtrl button (in CFeaturesDialog class) to read numbers (integer) from a text file and then pass those numbers in separate text files (in CDataDialog class), each file for every number. So I wrote:
void CFeaturesDialog::OnEnChangeMfceditbrowse1()
{
CString str;
m_browser.GetWindowTextW(str); //CMFCEditBrowseCtrl m_browser;}
void CDataDialog::OnBnClickedOk()
{
CStdioFile file(L"over1.txt", CFile::modeCreate |
CFile::modeWrite);
}e.g. if there 2 numbers in text file I open with CMFCEditBrowseCtrl I want to create over1.txt which will include the first number and over2.txt which will include the second number. How could I do that? Thank you in advance!
Where is the code to read the original file, and where do you store the two numbers? Once you have the numbers then writing them to their separate files is quite straightforward. It would be better if you generate the output file names dynamically, rather than hard coding them. It is also better to not use the
W
suffixes on Windows API calls; let the compiler generate the correct names based on your project settings. -
lolici wrote:
I am trying to use a CMFCEditBrowseCtrl button (in CFeaturesDialog class) to read numbers... e.g. if there 2 numbers in text file I open with CMFCEditBrowseCtrl...
The
CMFCEditBrowseCtrl
class does not open files. That class is simply an editable text box that optionally contains a browse button. Are the numbers in the source file (comma) delimited, or one per line? Since I do not know the answer to either of this, I will error on the side of the latter, something like:CStdioFile fileSource("source.txt", CFile::modeRead);
CStdioFile fileDest;
CString strLine;
CString strFile;
int num = 1;while (file.ReadString(strLine))
{
strFile.Format("over%d.txt", num++);
fileDest.Open(strFile, CFile::modeWrite);
fileDest.WriteString(strLine);
fileDest.Close();
}fileSource.Close();
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
Do I have to include the text file (source.txt) in project?? Cause I got the message "source.txt file not found". The content of the file can change any time by any user is that a problem??
lolici wrote:
Do I have to include the text file (source.txt) in project??
That's the name of the file you would retrieve from
CMFCEditBrowseCtrl
."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
lolici wrote:
Do I have to include the text file (source.txt) in project??
That's the name of the file you would retrieve from
CMFCEditBrowseCtrl
."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles