Maybe the problem lies here, considering that there is no bounds checking other than the use of at():

Code:

while (at(*pos) < '0'|| at(*pos) > '9') {
(*pos)++;
}

Again, please stop publicly inheriting from std::string. I know that inheritance is a novelty for you right now, but it is better that you do not start developing bad habits.

Originally Posted by Bjarne Stroustrup (2000-10-14)

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.

Again, the output:pos 0 end 0
pos 0 end -1
I do not understand how a loop which has that condition and that break would continue iterating. It should not be possible for that printf to execute while end < 0.

Okay, I guessing it's because size_t is an unsigned type....

Vis, deriving from std::string, yes, I understand this not a wise design move, I'm not planning on using it for anything except getting a feel for the syntax.

Last edited by laserlight; 02-22-2010 at 04:08 PM.
Reason: While loops are probably better than for loops with empty bodies.

Originally Posted by Bjarne Stroustrup (2000-10-14)

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.

1) so std::string::size_type is implementation specific, or always size_t?

std::string is a typedef for std::basic_string<char>, which has a default third template argument of std::allocator<char>. Now, the size_type member for std::basic_string is a typedef for the size_type member of this allocator. Since std::allocator<char>::size_type is a typedef for std::size_t, std::string::size_type is thus an alias for std::size_t.

Yeah, though it is a little less efficient than checking than comparing with '0' and '9'. A generic algorithm with a predicate could be used to get around that, but then writing a predicate currently often requires more boilerplate than is desirable, at least without the use of say Boost.Lamdba and such.

Originally Posted by Bjarne Stroustrup (2000-10-14)

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.