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 9145139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:26:22+00:00 2026-06-17T10:26:22+00:00

I have seen people output different strings together by using both << and +.

  • 0

I have seen people output different strings together by using both “<<” and “+”.

cout << firstname << lastname << endl;

versus:

cout << firstname + lastname << endl;

Is it better to use “<<” or does it not make much of a difference?

  • 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-06-17T10:26:23+00:00Added an answer on June 17, 2026 at 10:26 am

    Definitely, use << – concatenating the string will create a copy of the two strings pasted together. Whether it also allocates extra memory on top is a matter of how strings are implemented in the C++ library, but if the first and last names are “long enough” (bigger than 8-16 characters together), then it most likely WILL allocate memory (and then free it again when the temporary copy is no longer needed).

    The << operator will have very little overhead in comparison, so no doubt it is better.

    Of course, unless you do thousands of these things, it’s unlikely that you will have a measurable difference. But it’s good to not waste CPU cycles, you never know what good use they can be somewhere else… 😉

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

Sidebar

Related Questions

i have seen people localize their form using resource. put text data in resource
I have seen a few times people using -1 as opposed to 0 when
I have seen people using 2 methods to declare and define char * .
ok I have seen people using position:fixed to have a div follow the scroll.
in ASP.NET, I have seen people coding like this using (SqlConnection myConnection = new
I am working on a network programming and I have seen people using vector
I have seen people writing $(document).ready(function(){ }); and some writing $(function() { }); What's
I have seen some people in SO commenting that Singleton Pattern is an anti-pattern.
I have seen blogs and people saying Returning dataset/datatable from an ajax enabled wcf
I have seen a lot of people in the C++ community(particularly ##c++ on freenode)

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.