The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
arrays and string common libaries (newbie question)
Discuss arrays and string common libaries (newbie question) in the C Programming forum on Dev Shed. arrays and string common libaries (newbie question) C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

April 27th, 2003, 11:05 AM
|
|
Junior Member
|
|
Join Date: Apr 2001
Posts: 14
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
arrays and string common libaries (newbie question)
when studying my first C++ book i wonder why the hell c++ has limitations to arrays. why it can't be like in any other language that u just make an array grow by pushing values into it...
same for strings, other languages provide very efficient arithmetics to handle them...
so i wondered if someone already made a very common libary that overrides the standard c++ functionality in order to provide these - "essentials". otherwise i really first would need to do them on my own...
i am using Bloodshed Dev-C++ but shouldn't make a real diffrence...
sorry if this has been asked a thousand times already, i was not able to find it 
|

April 27th, 2003, 11:14 AM
|
 |
Contributing User
|
|
Join Date: Apr 2003
Location: Manchester, England
|
|
Hi,
Try looking up references to the vector class, which is the kind of dynamically sized array I think you're looking for. Try here:
http://www.cprogramming.com/tutorial/stl/vector.html
Also, there is a string class in C++, that isn't in C, which is *much* better than using an array of chars. There's a good guide which has exercises too here:
http://www.cse.fau.edu/~cot3002l/stringsC++/
Confused me for a while too, especially the vector notation, but stick with it, cos it's very useful!
Hope this helps :-)
__________________
Practise Random Kindness
|

April 27th, 2003, 11:40 AM
|
|
Junior Member
|
|
Join Date: Apr 2001
Posts: 14
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
THNX!
well the first link is somewhat - err - "wired" because this is somekind of half half thingy but anyway i gonna have a closer look, the second link seems really helpfull thanx.
but hm, this vector thing seems to b a common standard right so possibly my compiler knows it already?
i was looking for an array object that is like hmm -
able to b multidimensional.
and having the standard push shift pop unshift reverse concat... and the like functionality (like java, php, actionscript...) ...
is there perhaps another tutorial on this vector stuff where the rest of these r going to b mentioned or does the vector class just have these few commands mentioned on that site?
|

April 27th, 2003, 04:47 PM
|
 |
Throws Rocks
|
|
Join Date: Mar 2002
Location: Cincinnati, Ohio
Posts: 392
  
Time spent in forums: 6 h 31 m 7 sec
Reputation Power: 13
|
|
|
Re: arrays and string common libaries (newbie question)
Quote: Originally posted by gargoyle
when studying my first C++ book i wonder why the hell c++ has limitations to arrays. why it can't be like in any other language that u just make an array grow by pushing values into it... |
So that we can write overflow exploits of course 
__________________
Two things have come out of Berkeley, Unix and LSD.
It is uncertain which caused the other.
|

April 27th, 2003, 05:15 PM
|
 |
Contributing User
|
|
Join Date: Apr 2003
Location: Manchester, England
|
|
|
Sorry,
Forgot to mention that you want to
#include <vector>
as well. There are lots of methods that can be used in the vector class. Does Dev-C++ do drop-down lists of member attributes and methods? If it does, you could declare a vector object and then use that to see what's possible. Most of the names are pretty obvious, and you can at least search for the names of those that aren't as straightforward.
As, for a 2D array, you might be able to declare it of type:
vector<vector <int>>
which would be a 2D dynamically sized array of ints. Can anybody confirm this by the way, as I've only used them a couple of times... Might be a total load of rubbish :-)
Any time you see a class type with <> next to it, it's a 'template' which take a type as a parameter. Googling "c++ templates" should throw up lots of useful sites. I posted a question here on this topic myself recently - "Using static modifier with templates", and it contains a small class that uses templates (though part of the syntax was initially wrong, hence the post! :-) ).
Most c++ books will tell you more about them I should think, but as always it's just a case of knowing what terms to look out for...
Good luck!
|

April 27th, 2003, 08:24 PM
|
|
Junior Member
|
|
Join Date: Apr 2001
Posts: 14
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
Quote: | So that we can write overflow exploits of course |
so that u don't need to care anymore.
@ majelbstoat
or #include <vector.h> sure //err, btw. what the hell is the diffrence? something related to c's history right?
Quote: | Does Dev-C++ do drop-down lists of member attributes and methods? |
no < 
damn, i knew it, i need a reference!
Quote: | Most c++ books will tell you more about them I should think, but as always it's just a case of knowing what terms to look out for... |
yes, that obviously is a beginners problem 
allright, so i think i first gonna get myself another book also describing that template stuff...
Thanx alot majelbstoat
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|