error: ISO C++ forbids comparison between pointer and integer

here is some codes that I want to find the desired substring block in a string:

#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);

I chose returning iterator instead of index. However, debug give me this :

error: ISO C++ forbids comparison between pointer and integer. 

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]]'

Everything is fine when I used index method. I understand it must be a simple mistake but I hope someone can point out.


iter = std::find(iter, s.end(),"#STAGE");

It's wrong. You cannot find string in string, using std::find. Only character.

You can simply use

size_t pos = s.find("#STAGE");

and create iterator by

iter = s.begin() + pos;

if pos is not equal to std::string::npos.

Need Your Help

Linking dual (iphoneos and watchos) frameworks with same product name

xcode xcode7 ios-frameworks watch-os-2 watch-os

I recently had to duplicate my own frameworks to be able to link them from the native watchOS 2 extension, because the platform is different. So for every framework X I have an X-watchos counterpart.

3 tables SQL query

sql postgresql

I have three tables:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.