I have two really big numbers (max 23 digits/each) and I'd like to print them into a file as fast as it can be done. The lines in the file should look like: 

> 
> number1[space]number2[\n] eg. 123456789999999 99999965454644
> 
> 
> 

My approach is collecting the lines into one big buffer, and when the buffer is full, write it into the file, using fwrite(). 

The biggest problem is, that I don't know how to create one string from those 2 numbers and save them into one string/char array. As I mentioned the length of the string is variable, it can be only 3 characters or even 50.

```
const int OUT_BUFFER_SIZE = 65536;
string out_buffer[OUT_BUFFER_SIZE];
int out_size = 0;
FILE* output_file = fopen("result.out", "w");

void print_numbers(FILE* f, long long num1, long long num2)
{
  const int ELEMENT_SIZE = 50;

  char line[ELEMENT_SIZE];
  sprintf(line, "%lld %lld\n", num1, num2);
  out_buffer[out_size] = line;
  out_size++;

  if (out_size == OUT_BUFFER_SIZE)
  {
     fwrite(out_buffer, ELEMENT_SIZE, OUT_BUFFER_SIZE, f);
  }
}

fclose(output_file);

```

Is there any other way how to solve this problem? Thanks.

**EDIT1:**
I've tried two addtional approaches:

1) write numbers immediately into the file using `fprintf(f, "%lld %lld\n", num1, num2);`

2) using ofstream exactly the same way as @somnium mentioned.

I did measure both of them, and surprisingly, the 1) approach is 2x faster than the second.