Solved

Simple Question on std::string

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
best sources to up-to-date in C++? 8 89
Add values of each row in an array 3 63
Create a path if not exists 7 87
Issues with C++ Class 19 100
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

792 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