【发布时间】:2009-07-08 05:17:42
【问题描述】:
我正在编写一个简单的程序,它试图在给定数字之后找到下一个回文数。
至于现在,我被困在这一点上:
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";
}
当我使用 Microsoft Visual Studio 2008 编译这个时,我收到了这个错误:
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
我是在做一些愚蠢的事情还是我错过了什么? 如有任何帮助/建议,我将不胜感激。
【问题讨论】:
-
一开始我想知道你是不是在说 Sarah Palin。
标签: c++ visual-studio-2008 string iterator