QFile file("D:\Tcpview.exe"); if (file.exists()) { if ( file.size() > 2097152 ) { QMessageBox::information(this, tr("up file fail"), tr("Failed to up file, file size need < 2M.")); return; } if(!file.open(QIODevice::ReadOnly)) { QMessageBox::warning(this,tr("error"),tr("file no exit"),QMessageBox::Ok); return; } else { //////////////////////////////////// //fstream fin; ifstream fin("D:\Tcpview.exe", ios::in | ios::binary); //fin.open(filename2.c_str()); if(!fin) { cerr<<"open error!"<<endl; return; } int i = file.size(); QByteArray str = file.read(i); //写 //注意:不可使用string str = file.read(i); //会被截断 QFile file2("D:\Tcpview3.exe"); file2.open(QIODevice::WriteOnly); file2.write(str.data(), i); file2.close(); } }
c/c++开发分享qt实现读写二进制文件地址:https://blog.csdn.net/qq_33053671/article/details/107388240
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/c-cdevelopment/598871.html