Solved

Simple Question on std::string

Posted on 2004-09-28
2
233 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 500 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Find boost header files using gnu make (MinGW) on Win 7 11 112
C++ get user from AD  (VS6) 7 111
gdb doesn't stop on breakpoint 2 141
maximize the sum of fractions 33 76
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

751 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