Solved

Simple Question on std::string

Posted on 2004-09-28
2
199 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
  • 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now