Computer Science Canada string::substr(begin, end) |
Author: | Justin_ [ Sun Feb 12, 2006 10:10 pm ] | ||||
Post subject: | string::substr(begin, end) | ||||
Hi friends. There is something screwy going on with the substr method. Here's my code.
here is the output:
the problem is that for each substring there should only be one character. For instance, if the substring was (0,1) only one character is printed. If i=0, then i + 1= 1 and thus (0,1). It should consistantly only be one character but you see, each time it goes it gets to be more characters all the way up to i=8 and then it retracts again. Why? And how to fix? |
Author: | wtd [ Sun Feb 12, 2006 11:03 pm ] |
Post subject: | |
Try looking at the docs. basic_string::substr takes two arguments. The first is the starting index, and the second is the count of characters. You may wish to use the "at" member function instead, though. |
Author: | Justin_ [ Sun Feb 12, 2006 11:23 pm ] |
Post subject: | |
okay, thanks. |
Author: | wtd [ Mon Feb 13, 2006 1:33 am ] | ||
Post subject: | |||
Oh, and you're working too hard.
|
Author: | Justin_ [ Tue Feb 14, 2006 5:58 pm ] | ||
Post subject: | |||
Where there are comments I am unsure of what is taking place. Where there are not comments, I know what is taking place.
|
Author: | Andy [ Tue Feb 14, 2006 6:13 pm ] |
Post subject: | |
read up on wtd's stringstream tutorial found here |
Author: | wtd [ Tue Feb 14, 2006 6:34 pm ] |
Post subject: | |
Streams work a little differently with some values than with others. The std::hex variable, for instance, tells the stream that that next thing should be treated as a hexidecimal number. |
Author: | Justin_ [ Tue Feb 14, 2006 8:52 pm ] |
Post subject: | |
good stuff ![]() |
Author: | Justin_ [ Tue Feb 14, 2006 9:37 pm ] |
Post subject: | |
there doesn't seem to be an std::bin, how should I convert decimal to binary? |
Author: | wtd [ Wed Feb 15, 2006 12:00 am ] |
Post subject: | |
You're gonna have to do that one the hard way. But even then, it's not that hard. Before you start writing code, really think about how you'd do it by hand. |