This is not only true of perl and Java. In my C++ class I learned many, easily 20+ lines of code, difficult ways to create unlimited arrays. Once I looked at the standard headers included with C++, this was 4 years ago, I noticed vector.
#include <vector>
#include <iostream>
std::vector<char> array;
char c = 0;
while(c != 'X' || c != 'x')
{
//enter something or exit to quit
std::cin>>c;
array.push_back(c); //remind you of anything ;)
}
std::cout<<array.size()<<std::endl;
/* btw., the way I learned to get an arrays length was to create a sec
+ond int array as a counter*/
As for why the One Way, or more approapriately Best Way is ignored, that's a good question
"Cogito cogito ergo cogito sum - I think that I think, therefore I think that I am." Ambrose Bierce
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|