| |

VerySource

 Forgot password?
 Register
Search
View: 784|Reply: 7

Help: can't open the file with c ++

[Copy link]

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-3-22 21:30:02
| Show all posts |Read mode
Everyone help

void CSfsfdsfDlg :: OnOK ()
{
UpdateData ();
CStdioFile nameFile;
         try
{
          CString a;
nameFile.Open ("E:\\sfsfdsf\\plain.txt", CFile :: modeRead)) {}
         nameFile.ReadString (m_m);
          nameFile.Close ();
         
}
catch (CFileException)
{return;}
UpdateData (FALSE);
}

DEBUG ASSERTION FAILD
Reply

Use magic Report

1

Threads

6

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-7-1 10:45:01
| Show all posts
nameFile.Open("E:\\sfsfdsf\\plain.txt",CFile::modeRead)){}

What does this sentence mean, and there is one more), what's the use of the following {}!
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 United States

 Author| Post time: 2020-7-1 16:00:02
| Show all posts
Sorry

void CSfsfdsfDlg::OnOK()
{
UpdateData();
CStdioFile nameFile;
nameFile.Open("E:\\sfsfdsf\\plain.txt",CFile::modeRead)
         nameFile.ReadString(m_m);//Read a line from the file, read in m_m
          nameFile.Close();
         UpdateData(FALSE);
}

Error DEBUG ASSERTION FAILD
Reply

Use magic Report

1

Threads

15

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

Post time: 2020-7-1 16:30:01
| Show all posts
Can this code be compiled?
Reply

Use magic Report

1

Threads

15

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 Unknown

Post time: 2020-7-1 19:00:01
| Show all posts
DEBUG ASSERTION FAILD
------
Not a problem with this code
Reply

Use magic Report

0

Threads

14

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-7-1 19:45:01
| Show all posts
Here is a person who writes data to a file, compare it and see if you can find the error.
CString strValue;
strValue = "select xx from table ";
CStdioFile f;
if (f.Open( "g:\\a.doc" ,CFile::modeCreate|CFile::modeWrite)))
{
f.WriteString( strValue );
f.Close();
}
Reply

Use magic Report

0

Threads

14

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-7-1 23:15:01
| Show all posts
void CADlg::OnButton3()
{
// TODO: Add your control notification handler code here
CString str;
UpdateData();
CStdioFile nameFile;
         try
{
          CString a;
nameFile.Open("g:\\aa.txt",CFile::modeRead);
         nameFile.ReadString(str);
          nameFile.Close();
         
}
catch(CFileException)
{return;}
UpdateData(FALSE);

CWnd *pWnd;
pWnd=this->GetDlgItem(IDC_EDIT1);
pWnd->SetWindowText(str);
}

The above is the button click event, IDC_EDIT1 is the edit box, and the data in aa.txt can be read into the edit box.
Operation is correct...
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-7-20 13:45:01
| Show all posts
Thank you everyone, I found the problem
nameFile.Open("E:\\sfsfdsf\\plain.txt",CFile::modeRead) does not work
I changed nameFile.Open("E:\\sfsfdsf\\plain.txt",CFile::modeRead,NULL).
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list