錯誤記錄:QT中使用
no matching function for call to 'std::basic_ifstream<char>::basic_ifstream(QString&, const openmode&)' |
沒有匹配對。
看別人的:error: no matching function for call to 'std::basic_ifstream<char>::open(std::string&)
原因是C++的string類無法作為open的參數。
同樣,可以發現是fileName的類型不對,沒有匹配上。
QString fileName;
ifstream i_f_stream(fileName,ifstream::binary);
#include <fstream> using std::ifstream; ifstream i_f_stream(fileName,ifstream::binary);
需要轉換QString類型為const char*
見:【QT】QString類型轉換為const char* - ostartech - 博客園 https://www.cnblogs.com/wxl845235800/p/10796840.html
QString str =fileName; char *s; QByteArray//QString轉換為char* ba = str.toLatin1(); s = ba.data(); using std::ifstream; ifstream i_f_stream(s,ifstream::binary);
【參考】
error: no matching function for call to 'std::basic_ifstream<char>::open(std::string&) - 鐵樹銀花 - 博客園 https://www.cnblogs.com/cszlg/archive/2012/12/15/2910424.html
c++輸入文件流ifstream用法詳解 - ims的博客 - CSDN博客 https://blog.csdn.net/sinat_36219858/article/details/80369255