这是一些我想在字符串中找到所需子字符串块的代码:
#include <algorithm>
#include <string>
using namespace std;
...
unsigned int stage = 3;
string::iterator iter = s.begin();
string::iterator iter_next = s.end();
for (unsigned int i=0; i<stage; i++) {
iter = std::find(iter, s.end(),"#STAGE");
}
iter_next = std::find(iter, s.end(), "#STAGE");
string sub = string(iter, iter_next);
...
我选择返回迭代器而不是索引。但是,调试给我这个:
error: ISO C++ forbids comparison between pointer and integer.
c:\qtsdk\mingw\bin\..\lib\gcc\mingw32\4.4.0\include\c++\bits\stl_algo.h:-1:
In function '_RandomAccessIterator std::__find(_RandomAccessIterator, _RandomAccessIterator,
const _Tp&, std::random_access_iterator_tag) [with _RandomAccessIterator =
__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>,
std::allocator<char> > >, _Tp = char [7]]':
c:\qtsdk\mingw\bin\..\lib\gcc\mingw32\4.4.0\include\c++\bits\stl_algo.h:4224: instantiated
from '_IIter std::find(_IIter, _IIter, const _Tp&) [with _IIter =
__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>,
std::allocator<char> > >, _Tp = char [7]]'
当我使用索引方法时,一切都很好。我知道这一定是一个简单的错误,但我希望有人能指出。