Question about find_first_of of the STL string class

A

Allerdyce.John

I have my source string like this:

As i step thru the debugger, I can't understand why
namePosStart is 2
namePosEnd is 15

I expect:
namePosStart is 9
namePosStart is 11



a line: <TestCase name="testcase1">

Here is my code:

cout << "a line: " << aLine << endl;
string::size_type lastPos = aLine.find_first_of("<TestCase", 0);

if (lastPos != string::npos) {
string::size_type namePosStart = aLine.find_first_of("name=\"",
lastPos);
string::size_type namePosEnd = aLine.find_first_of("\"",
namePosStart + 1);
}

I print out 'aLine' to make sure I get the line correctly:
a line: <TestCase name="testcase1">

I appreciate if anyone can help.
 
A

Alf P. Steinbach

* (e-mail address removed):
I have my source string like this:

As i step thru the debugger, I can't understand why
namePosStart is 2
namePosEnd is 15

I expect:
namePosStart is 9
namePosStart is 11

You mean 10 and 15, respectively.

a line: <TestCase name="testcase1">

Here is my code:

cout << "a line: " << aLine << endl;
string::size_type lastPos = aLine.find_first_of("<TestCase", 0);

if (lastPos != string::npos) {
string::size_type namePosStart = aLine.find_first_of("name=\"",
lastPos);
string::size_type namePosEnd = aLine.find_first_of("\"",
namePosStart + 1);
}

I print out 'aLine' to make sure I get the line correctly:
a line: <TestCase name="testcase1">

I appreciate if anyone can help.

'find_first_of' searches for any element in a specified set (in this
case, a set of characters).

'find' searches for a substring.

Use 'find' instead of 'find_first_of'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top