[MFC] 외부파일 가져오기
이미지 파일일 경우 :
CFileDialog fileDlg(TRUE, NULL, NULL, OFN_READONLY, _T("image file(*.jpg;*.bmp;*.png;)|*.jpg;*.bmp;*.png;|All Files(*.*)|*.*||"));
if (fileDlg.DoModal() == IDOK)
{
CString path = fileDlg.GetPathName();
CT2CA pszString(path);
std::string strPath(pszString);
m_image = cv::imread(strPath),cv::IMREAD_UNCHANGED);
}
문서 파일일 경우 :
CFileDialog fileDlg(TRUE, NULL, NULL, OFN_READONLY, _T("Document files(*.txt;*.docx;*.pdf;)|*.txt;*.docx;*.pdf;|All Files(*.*)|*.*||"));
if (fileDlg.DoModal() == IDOK)
{
CString path = fileDlg.GetPathName();
CT2CA pszString(path);
std::string strPath(pszString);
std::ifstream file(strPath);
if (file.is_open())
{
std::string line;
while (std::getline(file, line))
{
// 파일의 각 줄을 처리합니다.
std::cout << line << std::endl;
}
file.close();
}
else
{
std::cerr << "파일을 열 수 없습니다." << std::endl;
}
}