Edit: Strictly speaking, the second code sample is only equivalent to the first when the loop executes at least once, i.e. when n>0. Otherwise, if the loop does not execute at all, ii is uninitialized so the first code sample would use an uninitialized variable.
Last edited by Peter_B; October 18th, 2012 at 07:30 AM.
Regardless of whether string2::len() does what it's supposed to, which I didn't check, this would never output the string length:
Code:
cout << "\nTamanho de S1: "; s1.len();
what you actually want probably rather is this:
Code:
cout << "\nTamanho de S1: " << s1.len();
In contrast, this does what you expect it to do:
Code:
cout << "\nS1 = "; s1.print();
This may seem paradox compared to the above, but it only "works" because string2::print() does the printing entirely on its own inside its implementation; the cout at the beginning of this line has nothing to do with that.
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
Bookmarks