|
-
Jan 19th, 2002, 08:27 PM
#1
Thread Starter
Fanatic Member
limit of array
Code:
int m[];
for(int i=0;i<=m[i];i++);
int i=0;
while(m[i] != '\n'){
...
i++;
}
which one is correct to scan till the ubound of hte array? i know VB has UBound, but i cant seem to figure out how to do it in C++
thanks
-nabeel
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
-
Jan 19th, 2002, 11:23 PM
#2
Lively Member
Why not just keep track of the elements in the array via some counter... then the loop is not neccessary...
-
Jan 20th, 2002, 11:21 AM
#3
Thread Starter
Fanatic Member
but i dont wanna have uneccessary variables.
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
-
Jan 20th, 2002, 11:21 AM
#4
Thread Starter
Fanatic Member
and after you use 2 or 3 arrays, the counters get kinda hard and messy to keep track of
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
-
Jan 20th, 2002, 12:09 PM
#5
Neither is correct. To first will loop until it finds a value in the array that is greater then or equal to i, while the other just loops until it finds (int)'\n' in the array. You have to understand that C++ arrays are not VB arrays. If you create an array like:
you will never have more or less then 10 elements in that array.
If you need a dynamic array, use an STL vector (#include <vector>, std::vector<int> x .
Z.
-
Jan 20th, 2002, 02:29 PM
#6
transcendental analytic
Arrays are C++ weak point (sometimes strong point) as they contain no information about their bounds, which undermines object orientation pretty much. Zaei's suggesting the vector as a implementation of a dynamical array, in VB dynamical arrays are declared without size, while in C++ you need your own implementation for the sake of flexibility.
You can obtain the size of (only) dynamically allocated memory with _msize() and so you could retrieve the size for any dynamical array with:
template<class T>int DynArraySize(T* a){return _msize(a)/sizeof( T);};
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Jan 20th, 2002, 02:45 PM
#7
Thread Starter
Fanatic Member
thanks 
any tuts on using vectors?
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|