Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6025899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:22:02+00:00 2026-05-23T04:22:02+00:00

In C++, which would be faster if repeated, say, 5000 times: cout << text!

  • 0

In C++, which would be faster if repeated, say, 5000 times:

cout << "text!" << endl;

or

my_text_file << "text!" << endl;

(writing to a file vs. cout-ing to the console)

Edit:

I ask because when writing to the console, you see all the text being printed which seems like it would slow down the loop. In a file, you arn’t seeing the text being printed, which seems as if it would take less time.

Just tested it:

Console: > 2000 ms using endl and \n

File: 40 ms with endl and 4 ms with \n

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T04:22:03+00:00Added an answer on May 23, 2026 at 4:22 am

    Writing to a file would be much faster. This is especially true since you are flushing the buffer after every line with endl.

    On a side note, you could speed the printing significantly by doing repeating cout << "text!\n"; 5000 times, then flushing the buffer using flush().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Which of theses scenarios would be faster? Scenario 1: foreach (var file in directory.GetFiles())
I am wondering which way would end up being faster, selecting elements by: $('element[href=#my_link]');
For example,We have a DWORD = $12345678 Which of the instructions would be faster
I have a label which would display strings from 0 ft to say 999
I need to make an excel file which would fetch data from connection to
Which one would be faster - a local web app gui made with something
Given the following two queries, which one would be faster (in theory) if there
Ok, I'm trying to figure out which way would be faster to read a
Which would be faster? Method A: UPDATE table1 SET table1.column1 = table2.column1 FROM table2
Which query would run faster? SELECT * FROM topic_info LEFT JOIN topic_data ON topic_info.id

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.