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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:28:28+00:00 2026-05-31T21:28:28+00:00

I have a problem using the string function erase with iterators. The function below

  • 0

I have a problem using the string function erase with iterators.

The function below takes names of input files and .ini files and creates the path for an output file. The path is defined as

dir + in_file + def_name + ini_file + ".txt"

I am using erase to erase the extensions of the input file names.

void Output::vDefault(string in, string ini)
{
 //save names
 strIn=in;
 strIni=ini;

 //get working dir
 char mydirectory[MAX_PATH] = {""};
 GetCurrentDirectory(MAX_PATH,mydirectory);

 //erase extensions
 strIn.erase(strIn.find_last_of('.'), strIn.end()); // error
 strIni.erase(strIni.find_last_of('.'), strIni.end()); // error

 //adr starts with folder
 strAdr=mydirectory;
 //and ends with name
 //address=dir+in_file+def_name+ini_file+.txt;
 strAdr+=strIn+DEFOUTNAME+strIni+".txt";    
}

Running the code causes the error below:

error C2664: 'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::erase(unsigned int,unsigned int)' : cannot convert parameter 2 from 'std::_String_iterator<_Elem,_Traits,_Alloc>' to 'unsigned int'

erase can take two iterators as first and last. Can you help me? I don’t know why it does not accept anything but int in my project.

  • 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-31T21:28:30+00:00Added an answer on May 31, 2026 at 9:28 pm

    string::find_last_of() doesn’t return an iterator, so it can’t match the iterator overload of string::erase().

    Fortunately, the string::erase() overload that takes an index for the position defaults to erasing from there to the end, so the following should work for you:

    strIn.erase(strIn.find_last_of('.'));
    strIni.erase(strIni.find_last_of('.'));
    

    Of course, the string had better actually have a '.' character in it…

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

Sidebar

Related Questions

I have a problem converting a string binary to a decimal I was using
I am using LaTeX and I have a problem concerning string manipulation. I want
I have a problem using the Java search function in Eclipse on a particular
I have problem with deserialize document to object using XmlSerializer class. Code my function
I have a function that replaces anchors' href attribute in a string using Php's
I'm using razor in webmatrix and I have a problem with the string special
I have a problem with casting a variable (see below) to a String so
Hello i have problem with putting logs using multithreading, my function loks like this
I've got a problem with using django's {% trans %} template function. I have
The Dropdownlist data binding using throw common function. In this have a problem in

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.