C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 27th, 2003, 11:05 AM
gargoyle gargoyle is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Posts: 14 gargoyle User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #2  
Old April 27th, 2003, 11:14 AM
majelbstoat's Avatar
majelbstoat majelbstoat is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: Manchester, England
Posts: 39 majelbstoat User rank is Sergeant (500 - 2000 Reputation Level)majelbstoat User rank is Sergeant (500 - 2000 Reputation Level)majelbstoat User rank is Sergeant (500 - 2000 Reputation Level)majelbstoat User rank is Sergeant (500 - 2000 Reputation Level)majelbstoat User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 h 4 m 46 sec
Reputation Power: 16
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

Reply With Quote
  #3  
Old April 27th, 2003, 11:40 AM
gargoyle gargoyle is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Posts: 14 gargoyle User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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?

Reply With Quote
  #4  
Old April 27th, 2003, 04:47 PM
GNUbie's Avatar
GNUbie GNUbie is offline
Throws Rocks
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2002
Location: Cincinnati, Ohio
Posts: 392 GNUbie User rank is Corporal (100 - 500 Reputation Level)GNUbie User rank is Corporal (100 - 500 Reputation Level)GNUbie User rank is Corporal (100 - 500 Reputation Level)GNUbie User rank is Corporal (100 - 500 Reputation Level) 
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.

Reply With Quote
  #5  
Old April 27th, 2003, 05:15 PM
majelbstoat's Avatar
majelbstoat majelbstoat is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: Manchester, England
Posts: 39 majelbstoat User rank is Sergeant (500 - 2000 Reputation Level)majelbstoat User rank is Sergeant (500 - 2000 Reputation Level)majelbstoat User rank is Sergeant (500 - 2000 Reputation Level)majelbstoat User rank is Sergeant (500 - 2000 Reputation Level)majelbstoat User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 h 4 m 46 sec
Reputation Power: 16
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!

Reply With Quote
  #6  
Old April 27th, 2003, 08:24 PM
gargoyle gargoyle is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Posts: 14 gargoyle User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > arrays and string common libaries (newbie question)

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap