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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T23:55:24+00:00 2026-05-11T23:55:24+00:00

I am writing a simple program, which is trying to find next palindrome number

  • 0

I am writing a simple program, which is trying to find next palindrome number after given number.

As for now, I am stuck at this point:

string::iterator iter; // iterators for the string
string::iterator riter; 


//testcases is a vector<string> with strings representing numbers.
for (unsigned int i = 0; i < testcases.size() ; ++i) {
    iter = testcases[i].begin();
    riter = testcases[i].end();

    while ( !isPalin(testcases[i]) ) { //isPalin(string) is a function
                                       //which is checking if given string
                                       //is a palindrome

        //if n-th digit from the end is different from the
        //n-th digit, then I want to replace latter one, so they will 
        //be the same.
        if ( *iter != *riter ) {
            testcases[i].replace(riter, riter, *iter);
        }

        ++iter; // advancing forward iterator;
        --riter; // advancing backward iterator;
    }
    cout << testcases[i] << " -> ok\n";
}

When I am compiling this one using Microsoft Visual Studio 2008, I am getting this error:

Compiling...
main.cpp
.\main.cpp(53) : error C2664: 'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::replace(unsigned int,unsigned int,const std::basic_string<_Elem,_Traits,_Ax> &)' : cannot convert parameter 1 from 'std::_String_iterator<_Elem,_Traits,_Alloc>' to 'unsigned int'
        with
        [
            _Elem=char,
            _Traits=std::char_traits,
            _Ax=std::allocator
        ]
        and
        [
            _Elem=char,
            _Traits=std::char_traits,
            _Alloc=std::allocator
        ]
        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

Am I doing something stupid or am I missing something?
I would be grateful for any help / suggestion.

  • 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-11T23:55:24+00:00Added an answer on May 11, 2026 at 11:55 pm

    About the code you have:

    Why don’t you just assign the values at the end of the two iterators?

    if ( *iter != *riter ) {
       *riter = *iter;
    }
    

    As Oli pointed out, there are other problems in the code, the first of which is the fact that you are setting riter to be string.end(), witch is a non-dereference-able iterator. end() iterators are always one past the end, and thus the use above will try to write beyond the assigned memory.

    Maybe you should try using .rbegin() instead. It will provide a reverse iterator pointing to the last element that moves towards the beginning of the string as you increment it.

    On the algorithm:

    If your intention is finding the next number that is a palindrome, I am not sure that the algorithm you have implemented is correct. As an example, if the input number is 123456 the algorithm will detect that it is not a palindrome and will convert to 12345_1_ which is smaller than the original number.

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

Sidebar

Ask A Question

Stats

  • Questions 133k
  • Answers 133k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The answer above should work fine except for a minor… May 12, 2026 at 6:32 am
  • Editorial Team
    Editorial Team added an answer This should do it: var myCellText = myCell.childNodes[0].innerHTML; May 12, 2026 at 6:32 am
  • Editorial Team
    Editorial Team added an answer If this is a Swing application, you should use a… May 12, 2026 at 6:32 am

Related Questions

I'm trying to do what I think is a simple thing under Linux. I
I am writing a server program with one producer and multiple consumers, what confuses
I am writing a program that's similar to a shell. Once started up, there's
I am writing a winforms app in which a user selects an item from

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.