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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:51:19+00:00 2026-05-30T01:51:19+00:00

I am trying to use the STL function for_each to convert a string into

  • 0

I am trying to use the STL function for_each to convert a string into lower case and I have no idea what I am doing wrong. Here’s the for_each line in question:

clean = for_each(temp.begin(), temp.end(), low);

Where temp is a string that is holding a string. And here’s the function that I wrote for low:

void low(char& x)
{
x = tolower(x);
}

And the compiler error that I keep getting is as such:

error: invalid conversion from void (*)(char&) to char [-fpermissive]

What am I doing wrong?

EDIT:
Here is the whole function that I am writing:

void clean_entry (const string& orig, string& clean)
{
string temp;
int beginit, endit;

beginit = find_if(orig.begin(), orig.end(), alnum) - orig.begin();
endit = find_if(orig.begin()+beginit, orig.end(), notalnum) - orig.begin();

temp = orig.substr(beginit, endit - beginit);

clean = for_each(temp.begin(), temp.end(), low);
}
  • 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-30T01:51:20+00:00Added an answer on May 30, 2026 at 1:51 am

    for_each‘s return-value is the function that you passed it — in this case, low. So this:

    clean = for_each(temp.begin(), temp.end(), low);
    

    is equivalent to this:

    for_each(temp.begin(), temp.end(), low);
    clean = low;
    

    when what you really want is probably this:

    for_each(temp.begin(), temp.end(), low); // note: modifies temp
    clean = temp;
    

    (or you can just eliminate temp to begin with, and use clean throughout).

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

Sidebar

Related Questions

I'm trying to use stl algorithm for_each without proliferating templates throughout my code. std::for_each
I was trying to use an STL list in C++ and I arrived into
I'm trying to use partial application of function arguments so I can use STL's
I'm trying to use stl sort() in a class function. I would like to
I'm trying to write predicate function for use with STL algorithms. I see that
I trying to convert some loops in my code to use the for_each functionality
I have a C++ class where I'm trying to use std::bind1st to bind a
I'm trying to use STL to solve the following problem (I don't want to
I am trying to use std::for_each to output the contents of vectors, which may
We are trying to use the std::deque erase member function. The return value 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.