Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Simple Question on std::string

Posted on 2004-09-28
2
Medium Priority
?
248 Views
Last Modified: 2010-04-01
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
Comment
Question by:jjacksn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 2000 total points
ID: 12174670
>>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
 
LVL 86

Expert Comment

by:jkr
ID: 12174676
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question