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

The Archive Base Latest Questions

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

Is it me or are there no standard trim functions in the c or

  • 0

Is it me or are there no standard trim functions in the c or c++ library? is there any single function that acts as a trim? If not can anyone tell me Why trim is not part of the standard library? (i know trim is in boost)

My trim code is

std::string trim(const std::string &str) {     size_t s = str.find_first_not_of(' \n\r\t');     size_t e = str.find_last_not_of (' \n\r\t');      if(( string::npos == s) || ( string::npos == e))         return '';     else         return str.substr(s, e-s+1); } 

test: cout << trim(‘ \n\r\r\n \r\n text here\nwith return \n\r\r\n \r\n ‘); -edit- i mostly wanted to know why it wasnt in the standard library, BobbyShaftoe answer is great. trim is not part of the standard c/c++ library?

  • 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. 2026-05-11T04:12:02+00:00Added an answer on May 11, 2026 at 4:12 am

    The reason trim() isn’t in the standard library is that when the last standard was made, they had to strike a balance between formalizing current behavior (adding nothing new, just stabilizing what already existed), and adding new functionality. In general, they preferred not to add a feature unless it either 1) would be impossible otherwise, or 2) there were significant drawbacks to using third-party libraries instead. Making too many changes would

    • break compatibility with existing code (which may have defined its own trim()
    • Add more work for compiler writers (who already had a huge amount of work ahead of them)
    • Make the language more complex to learn and use.

    With trim(), there are no major interoperability issues. As long as your third-party trim() implementation takes a string and returns a string, we don’t really care where it’s defined. So it’s not really necessary In the standard library. It can be easily supplied by other libraries.

    By contrast, something like the string class or vector, are classes that the standard library must supply, because if you use a custom string class, only string operations from that library will work. With a standard library string, third-party libraries can target this common string definition, and everyone wins.

    When the last standard came out, Herb Sutter wrote a post describing this very well here

    Of course, it would be nice to have a trim() function, but they had bigger fish to fry. They had to standardize all the basics first. I don’t think C++0x will add a trim function, but it will add a lot of other convenience utilities that back in ’98 were considered ‘unnecessary’ or too specialized.

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

Sidebar

Related Questions

Is there any standard way of debugging Javascript on a webpage that's being accessed
Is there a standard Java library that handles common file operations such as moving/copying
Is there a standard location for j_security_check so that i can take a look
Is there an standard XQuery function that will return a 'canonical' path for a
Is there a standard, cross platform number generator/algorithm/library that if seeded with the same
Is there any standard way to create a transient class in CLOS; that is,
Is there standard structure or library in C++ (or C++11) that is something like
Is there standard function to enumerate an F# sequence that works like Python's enumerate()
Is there a standard convention for the types of files that go in \Windows\
Is there a standard C function similar to strtol which will take a char*

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.