@anda_skoa, thanks. I found an amazing thing happens here. for data[m][n] (double (*data)[n]; data = double[m][n]) when m>n it gives me right myfile.txt but when m<n it gives a file in size of zero!!! for example when m=599 and n=600 it gives me a file in size of zero and returns:"The program has unexpectedly finished." but when m=601 and n=600 it gives me a file in size of 2,344kB
even when m is so larger than n, there is no false but if n is only one bigger that m, its not ok!!!
for example:
#include <QApplication>
#include <QFile>
#include <QDebug>
#include <QDataStream>
int main(int argc, char *argv[])
{
QFile myfile
("d:/test.txt");
{
qDebug() << "can not open to write";
return 1;
}
double (*data)[600];
data = new double[599][600];//now is not ok but if i define data = new double[601][600] it gives me right file!!!
for(int i=0; i<599; i++)
{
for(int j=0; i<600; i++)
{
data[i][j] = (i+1)*(j+1);
}
myfile.write((char *)(&(data[i][600])), sizeof(double));
}
//myfile.write((char *)(&(data[0][0])), 599*600*sizeof(double)); when m>n this is true also
myfile.flush();
myfile.close();
return 0;
}
#include <QApplication>
#include <QFile>
#include <QDebug>
#include <QDataStream>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QFile myfile("d:/test.txt");
if(!myfile.open(QIODevice::WriteOnly))
{
qDebug() << "can not open to write";
return 1;
}
double (*data)[600];
data = new double[599][600];//now is not ok but if i define data = new double[601][600] it gives me right file!!!
for(int i=0; i<599; i++)
{
for(int j=0; i<600; i++)
{
data[i][j] = (i+1)*(j+1);
}
myfile.write((char *)(&(data[i][600])), sizeof(double));
}
//myfile.write((char *)(&(data[0][0])), 599*600*sizeof(double)); when m>n this is true also
myfile.flush();
myfile.close();
return 0;
}
To copy to clipboard, switch view to plain text mode
You are right I need no QDataStrem and I can use QFile directly.
thanks for anymore help
Bookmarks