#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2001
    Posts
    14
    Rep 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 :(
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Location
    Manchester, England
    Posts
    39
    Rep Power
    17
    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
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2001
    Posts
    14
    Rep 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?
  6. #4
  7. Throws Rocks
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2002
    Location
    Cincinnati, Ohio
    Posts
    392
    Rep Power
    14

    Re: arrays and string common libaries (newbie question)


    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.
  8. #5
  9. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2003
    Location
    Manchester, England
    Posts
    39
    Rep Power
    17
    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!
    Practise Random Kindness
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2001
    Posts
    14
    Rep Power
    0
    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?

    Does Dev-C++ do drop-down lists of member attributes and methods?
    no <:(
    damn, i knew it, i need a reference!

    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

IMN logo majestic logo threadwatch logo seochat tools logo