I'm not to much familiar with c++ , just wanted to create a text file and write (n) bytes in it , as fast as possible. Using vc6 , any help will be appreciated.
Asked
Active
Viewed 2,383 times
1
-
1vc6? Time to think about upgrading. When you say bytes, do you mean ASCII characters? – Bathsheba Dec 05 '13 at 21:10
-
bytes(just simple characters) e.g. space – user2831683 Dec 05 '13 at 21:13
-
there are no "simple characters", really. There are "simple bytes", but as soon as you start talking about characters and text, reality gets more complex. – hyde Dec 05 '13 at 21:18
2 Answers
1
Fastest to write bytes... Use std::fwrite
. Example copied and slightly edited:
/* fwrite example : write buffer */
#include <cstdio>
int main ()
{
FILE * pFile;
char buffer[] = { 'x' , 'y' , 'z' };
pFile = std::fopen ("myfile.bin", "wb");
if (!pFile) return 1;
std::fwrite (buffer , sizeof(char), sizeof(buffer), pFile);
// code ignores fwrite error, in real app check it!
std::fclose (pFile);
// code ignores fclose error, in real app check it!
return 0;
}
This might not be what you really want to do, but it is the answer to the question... To get possibly better answer, tell what kind of data you actually want to write and with what constraints (in a new question, after experimenting with this)...

hyde
- 60,639
- 21
- 115
- 176
0
Fput is good for strings, fwrite for anything. You can use ofstream, and manipulate with its buffer for perfomance check this: Does C++ ofstream file writing use a buffer? .

Community
- 1
- 1

mugiseyebrows
- 4,138
- 1
- 14
- 15