.txt
파일을 디스크에 저장하기 위해 다른 이름으로 저장 단추가있는 MFC C++ 응용 프로그램을 작성했습니다. 파일 덮어 쓰기에 대한 추가 확인을 추가하려고합니다 (동일한 파일 이름의 파일이있는 경우 이전 파일을 덮어 쓰려면 사용자에게 쿼리해야 함). 아래 코드를 사용하여이 작업을 시도했지만 실제로 작동하지 않습니다. MessageBox에서 No를 클릭하면 Save As File 대화 상자가 다시 열리고 두 개의 오류가 표시됩니다. 첫 번째 파일은 Debug assertion failed
이고 두 번째 파일은 Encountered an improper argument
입니다. 어떻게해야합니까? 이것은 코드 :MFC 파일 저장 대화 상자
char strFilter[] = { "Text Files (*.txt)|*.txt|" };
CFileDialog FileDlg(FALSE, CString(".txt"), NULL, 0, CString(strFilter));
while(true)
{
if(FileDlg.DoModal() == IDOK) // this is the line which gives the errors
{
agendaName = FileDlg.GetFileName(); //filename
agendaPath = FileDlg.GetFolderPath(); //filepath (folders)
if(model->agendaExists(CSToString(agendaPath+TEXT("\\")+agendaName))) // there is another file called the same way
{
if(MessageBox(TEXT("A file with the specified name already exists. Overwrite?"), TEXT("File exists"), MB_YESNO) != 6) // user clicked NO (do not overwrite file)
{
continue;
}
}
model->sendToFile(CSToString(agendaPath+TEXT("\\")+agendaName)); // the file is unique so the agenda named agendaName found at path agendaPath is saved
return;
}
}
오류가 라인 7 만 while
내지 2 루프에서 발생하는 것으로 언급되어야한다.
알고 있지만 파일 이름과 파일 경로가 모두 필요합니다. 위와 같이, 그것은 효과가 있었다. 감사! –