Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 252
  • Last Modified:

Simple Question on std::string

I have code:

      size_t nPos1, nPos2;
            string fieldTag;
            string oldData;
            string newData;

            //Get the action:
            nPos1 = line.find(tag_start);
            nPos2 = line.find( " ", nPos1 + tag_start.length); //nPos2 now has the index of the first space
            

the last line is throwing a compilier error because nPos + tag_start.length is not a valid operation.  I thought std::string.legnth (tag_start is a std::string) returns type size_t?  What am I doing wrong?
0
jjacksn
Asked:
jjacksn
  • 2
1 Solution
 
jkrCommented:
>>What am I doing wrong?

That should be

nPos2 = line.find( " ", nPos1 + tag_start.length()); //nPos2 now has the index of the first space

It is 'tag_start.length()', not 'tag_start.length'. You're calling a member function here.
0
 
jkrCommented:
Hum that is assuming that 'tag_start' also is a std::string - if it is a char*, you should use

nPos2 = line.find( " ", nPos1 + strlen(tag_start));

0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now