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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:20:06+00:00 2026-05-29T06:20:06+00:00

I have a new function called removeInelligibleCharsFromTargetName . void removeInelligibleCharsFromTargetName(string *targetName) { for(int i

  • 0

I have a new function called removeInelligibleCharsFromTargetName.

void removeInelligibleCharsFromTargetName(string *targetName)
{
    for(int i = 0; i < targetName->length(); i++)
    {
        for(int j = 0; j < ineligibleChars.length(); j++)
        {
            if(targetName[i] == ineligibleChars[j])
                targetName[i] = '_';
        }
    }
}

The problem is when I try the comparison in the if loop I get the following error:

error C2678: binary ‘==’ : no operator found which takes a left-hand operand of type ‘std::string’ (or there is no acceptable conversion)
32> c:\program files\microsoft sdks\windows\v6.0a\include\guiddef.h(192): could be ‘int operator ==(const GUID &,const GUID &)’ while trying to match the argument list ‘(std::string, char)’

But put that exact same nested loop back where I call it instead of calling the function it works fine.

Can someone tell me whey it won’t work in a function but works fine outside the function. No doubt its something about it being a pointer but I dont know what.

  • 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-29T06:20:07+00:00Added an answer on May 29, 2026 at 6:20 am

    Why are you passing a pointer to a string? That’s a really bad idea. Pass a reference.

    void removeInelligibleCharsFromTargetName(string& targetName)
    {
        for(int i = 0; i < targetName.length(); i++)
        {
            for(int j = 0; j < ineligibleChars.length(); j++)
            {
                if(targetName[i] == ineligibleChars[j])
                    targetName[i] = '_';
            }
        }
    }
    

    The problem is that when you have a pointer, targetName[i] is the same as *(targetName+i). That is the equivalent of indexing into an array of strings. If you don’t have an array of strings this would only lead to undefined behaviour. You were lucky that the code doesn’t compile (can’t compare a string with a character) and the compiler caught the error. If it happened to compile, when you ran it you would probably observe some very strange behaviour.

    When you have a string, or a reference to one, targetName[i] invokes the operator[] on the string, which indexes into the string and actually gives you a character.

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

Sidebar

Related Questions

I have this function... private string dateConvert(string datDate) { System.Globalization.CultureInfo cultEnGb = new System.Globalization.CultureInfo(en-GB);
I'm new in using boost and have a problem. I need shared_mutex function in
using C#, i have a function called addmember. it uses linq to create new
I have a function called gett(int) that returns a series upon every call. It
I would like to temporarily override the kill-new function. I have a way I
I have a function that receives three different people objects and generates a new
I have used Javascript onlaod like this: function check() { var pic = new
I have an ImageButton with an onclientclick js function attached: deleteButton = new ImageButton();
I am new to programming. I have been trying to write a function in
I have a strange one. Create a new form. Then add the following function

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.