33,311
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <iomanip>
#include <fstream>
#include <time.h>
int main(int argc, char * argv[])
{
// 生成文件,大小为7.62 MB (8,000,000 字节)
// std::ofstream of("double.txt", std::ios_base::binary);
// if (!of.is_open())
// perror("open double.txt error:");
// double d;
// for (int i = 0; i < 2000000; ++i) {
// d=i;
// of.write((char *)&d, sizeof(d));
// }
time_t tm=time(NULL);
std::ifstream ifs("double.txt",std::ios_base::binary);
if(!ifs.is_open())
perror("open double.txt error:");
int i=0;
double buf_d[10][10000]; // 2000000崩溃了,所以要小点
ifs.read((char *)&buf_d, sizeof(buf_d));
std::cout<<i<<" use "<<time(NULL)-tm<<" seconds."<<std::endl;
for (int i = 0; i < 10; ++i) {
std::cout<< buf_d[i][9999] <<std::endl;
}
return 0;
}
#include <iostream>
#include <iomanip>
#include <fstream>
#include <time.h>
int main(int argc, char * argv[])
{
// 生成文件,大小为7.62 MB (8,000,000 字节)
// std::ofstream of("double.txt", std::ios_base::binary);
// if (!of.is_open())
// perror("open double.txt error:");
//
// for (int i = 0; i < 2000000; ++i)
// of.write((char *)&i, sizeof(i));
time_t tm=time(NULL);
std::ifstream ifs("double.txt",std::ios_base::binary);
if(!ifs.is_open())
perror("open double.txt error:");
int i=0;
double d=0;
while(!ifs.eof())
{
ifs.read((char *)&d, sizeof(d));
++i;
}
std::cout<<i<<" use "<<time(NULL)-tm<<" seconds."<<std::endl;
return 0;
}
#include <iostream>
#include <iomanip>
#include <fstream>
#include <time.h>
int main(int argc, char * argv[])
{
// 生成文件,大小为7.62 MB (8,000,000 字节)
// std::ofstream of("double.txt", std::ios_base::binary);
// if (!of.is_open())
// perror("open double.txt error:");
//
// for (int i = 0; i < 2000000; ++i)
// of.write((char *)&i, sizeof(i));
time_t tm=time(NULL);
std::ifstream ifs("double.txt",std::ios_base::binary);
if(!ifs.is_open())
perror("open double.txt error:");
int i=0;
double buf_d[20000]; // 2000000崩溃了,所以要小点
ifs.read((char *)&buf_d, sizeof(buf_d));
std::cout<<i<<" use "<<time(NULL)-tm<<" seconds."<<std::endl;
return 0;
}
#include <iostream>
#include <iomanip>
#include <fstream>
#include <time.h>
int main(int argc, char * argv[])
{
/*生成文件,大小为21 977 773(21M)
std::ofstream of("double.txt");
if(!of.is_open())
perror("open double.txt error:");
int i=0;
for(;i<2000000;++i)
of<<i+1.1<<std::endl;
*/
time_t tm=time(NULL);
std::ifstream ifs("double.txt");
if(!ifs.is_open())
perror("open double.txt error:");
int i=0;
double d=0;
while(!ifs.eof())
{
ifs>>d;
++i;
}
std::cout<<i<<" use "<<time(NULL)-tm<<" seconds."<<std::endl;
return 0;
}