best way to stream to file

Hallo,
I am new to C++. I have only experience with C#.
I have the below problem:

in a loop i receive a buffer and I want so vae it (stream it??) to file. What is the best and fastest way to do it?

in pseudocode I would have something like

byte[920000] bb
open myfile for writing

loop
{
wait for bb to be ready
save timestamp to myfile
save buffer to myfile
}

close myfile

the size of the buffer is quite big, somwhere in between 900K and little bit more than 1 MB. the loop expects the buffer to be ready about 30/40 times per second.

thk for any kind of adive you can give me.
Nicola
Lol that site is still going?

Basic usage of ofstream with no error checking. Also avoid use constants ( the 256 ) I did it out of ease.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <fstream>

int main()
{
	char buffer[256];

	// Do something with buffer

	std::ofstream ofs("File.txt");

	for(int i = 0; i < 256; i++)
		ofs << buffer[i];

	return 0;
}
Hi Megatron, thx for your reply.

@Little Bobby Tables: thx for spending time to read my post. Before ending up here I have goggled a lot. I could find many ways to save data to file but, if you had read carefully, you would have noticed I was asking for "the best" way. This requires a human brain to analyze the problem, apply knowledge, eventually propose a solution. I think search engines are not capable of doing that yet. Also, why should you reply "google it"? Do not have the answer? skip the post.
i did read your post carefully. what did you think i linked to? a bunch of robots generating code? of course it was "analysed" by humans. i really doubt you googled, because otherwise you would have found std::fstream, and i really doubt you would have found any other good solution, except perhaps a boost solution. i replied with google it, because, as should be common sense, forums arent meant for lazy posting. you should attempt to find your answer on google and then post it on a forum.
Topic archived. No new replies allowed.