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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:27:31+00:00 2026-06-04T03:27:31+00:00

In the language I was first introduced to, there was a function repeat() ,

  • 0

In the language I was first introduced to, there was a function repeat(), that took a string, and repeated it n times. For example, repeat ("hi", 3) gives a result of "hihihi".

I did have quite a few times that I used this function, but to my dismay, I’ve never found something similar in C++. Yes, I can easily make my own, or make it easier to use, but I’m kind of surprised that it isn’t included already.

One place it would fit in really well is in std::string:

std::string operator* (const std::string &text, int repeatCount);
std::string operator* (int repeatCount, const std::string &text);

That would allow for syntax such as:

cout << "Repeating \"Hi\" three times gives us \"" << std::string("Hi") * 3 << "\"."

Now that in itself isn’t all too great yet, but it could be better, which brings me to my other part: literals.

Any time we use the string operators, such as operator+, we have to make sure one argument is actually a string. Why didn’t they just define a literal for it, like ""s? Literal suffixes not beginning with an underscore are reserved for the implementation, so this shouldn’t conflict seeing as how this could have been added before anyone actually started making their own.

Coming back to the repeat example, the syntax would simply be:

cout << "123"s * 3 + "456"s;

This would produce:

123123123456

While at it, one for characters could be included as well, to satisfy cout << '1's + '2's;

Why weren’t these two features included? They definitely have a clear meaning, and make coding easier, while still using the standard libraries.

  • 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-04T03:27:33+00:00Added an answer on June 4, 2026 at 3:27 am

    Well, as for the multiplication, it’s not really in C++’s philosophy: languages like Ruby come “batteries included” and with the “principle of least surprise”. They are intended to have lots of these little niceties as an above-and-beyond-the-minimum feature. C++ is a system level language which is intended to be “closer to the metal”, which is abundantly clear in that a string isn’t even a core data type of the language, but a library-provided addon. Even FORTRAN has a native string type, so you can see how low-level C++ is positioned to be. This is intentional: what if you’re programming an embedded chip with 1K storage and have no use for strings? Just don’t include ’em.

    Anyway, it’s not 100% clear what the multiplication operator is supposed to do. In other words, in the core language and libraries of C++, no feature gets in unless it seems that almost everyone would agree on the proposed functionality. It’s got to be really universal.

    I for one might think that “123” * 3 could give “369” – multiply any digits by 3. I further propose that this interpretation is “sane” enough to keep your repeat operator interpretation from being the only unambiguous interpretation.

    The literal notation is far easier and more clear to answer: std::string is a part of the standard library, which is one level of abstraction above the language syntax itself. In other words, the literal notation would bust through the level of abstraction that separates “language features” and “the library that you can expect to be bundled with your compiler”.

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

Sidebar

Related Questions

When I first became interested in programming, I took a class that introduced me
When I took my first programming course in university, we were taught that global
Hi all I was wondering is it true that the first-language of monitors is
The first language I learnt was PHP, but I have more recently picked up
C++ was the the first language I've learnt so dividing source code into .h
I have been programming in Java (my first language) for about six months and
I'm a beginner programmer and I'm learning my first language, C. I'm learning mostly
I am new to programming and am learning Python as my first language. I
sorry in advance for any orthographic mistakes (english is not my first language). I
C++ was the first programming language I really got into, but the majority of

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.