From faa5b755aa9736626f49091bfaff24ffed81d593 Mon Sep 17 00:00:00 2001 From: nchn27 <46332369+nchn27@users.noreply.github.com> Date: Sat, 4 Jul 2020 01:55:14 -0400 Subject: [PATCH] Update IO_Speed.mdx --- content/2_General/IO_Speed.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/2_General/IO_Speed.mdx b/content/2_General/IO_Speed.mdx index 0652d12..04a74d8 100644 --- a/content/2_General/IO_Speed.mdx +++ b/content/2_General/IO_Speed.mdx @@ -361,7 +361,7 @@ else: ## Fast Output -In general, it may also be faster to store the answer all in a single `string` (C++) or `StringBuffer` (Java) and outputting it with a single function call. This method avoids the overhead of calling an output method many times, especially if the output is generated in many parts. +In general, it may be faster to store the answer all in a single `string` (C++) or `StringBuffer` (Java) and outputting it with a single function call. This method avoids the overhead of calling an output method many times, especially if the output is generated in many parts. ### C++ When printing many lines in C++, it may be faster to use the newline character `\n` in place of `endl`. Output streams in C++ (such as `cout` and `ofstream`) are buffered, meaning that they don't immediately print their output, but store some of it. At some point, the buffer's contents are written (i.e. "flushed") to the output device, whether it be the standard output stream or a file. Buffering the output helps with efficiency if accessing the output device (like a file) is slow. Because `endl` flushes the output, it may be faster to use `\n` instead and avoid unnecessary flushes.