What is the fastest way to read and write file in C++ ?
You don't indicate the type of data. It's difficult to answer your question without knowing the type of data.
If it's character oriented data (\n delimited), use istream and ostream, use >> or getline and << as appropriate
If it's fixed size record oriented data or binary data, use istream::read and ostream::write or operating system calls.
Sorry I was not clear enough. Even when the data is plain text you can read and write it in binary format. Since you asked about the fastest way you should prefer the binary format. Here is a little speed comparison:
Controlling the size of your writes will help a lot more than you might think.
In other words, your best throughput will be to fill a memory buffer and write full and large blocks of data.
Your device probably supports 4k writes as the smallest size. Every time you write a file you have overhead which will impact performance. So the larger sized files you can write means less overhead, hopefully better performance.