Recently I was trying to write pointcloud data to .txt file by using C++ in Visual Studio 2010. At the beginning I used ostream to output the data, but I found it slow when writing the data.
My code :
std::ofstream outfile;
outfile.open(filename.c_str());
for(int index = 0;index < pointcloud.size();index++){
outfile<<pointcloud[index].x<<pointcloud[index].y<<pointcloud[index].z
<<pointcloud[index].r<<pointcloud[index].g<<pointcloud[index].b<<'\n';
}
outfile<<std::endl;
The output pointcloud is very huge, almost 0.5G. It takes minutes to write into .txt file. How can I improve the speed of writing down the data? I thought it might be the problem of the size of cache buffer, but not sure. Can someone help me with this?