I read that vectors and arrays are almost the same. Could you explain this to me?

Member Avatar for iamthwee

ok they are resizable array! That's good, I mean instead of just creating a big array and wasting memory we can use vectors.

Can we drop the .h from all the C++ headers? But it works for me even though I use them.

vectors are much like arrays

#include <vector>
int main()
{
//standard way to create an array
int myarray[someconstsize] = { 0 }; //assigns all values to default zero
 
//vector declaration
vector<int> myvec;//declares an int type vector
 
//adding data to them
 
myarray[0] = 4;
 
myvec.push_back(4); //adds four to the end

this is in no ways the end all be all deffination, but a somewhat decent look at em :)

commented: You explanations are sooo cute! +12
Member Avatar for iamthwee

I'm not even sure you can use stl stuff in turbo c. (old one that it).

When you finish your edjumacation and if you want to learn proper c++, get dev-cpp from bloodshed.

I have dev-c++ but I didn't use it because it didn't support graphics

I have dev-c++ but I didn't use it because it didn't support graphics

could always work with Visual Studio

i happen to find this environment quite fun and easy to work in.

Member Avatar for iamthwee

Dev is better for pure c++, VS tends to convolute what is standard c++. Such as when killer typo mistook

for each

As standard c++.

Dev is better for pure c++, VS tends to convolute what is standard c++. Such as when killer typo mistook

for each

As standard c++.

heh it's actually because of a setting in VS which can be turned off to disable ;)

dont try and set the standard with my mistake that would be a mistake in itself :)

i've asked a couple professionals (30+ years experience in software/hardware..etc development, one of which is currently head of product research development) and when i asked about the compiler they use, they replied that they use microsofts products.

when i asked about other compilers, like borland, turbo, bloodshed they just laughed them off.

Member Avatar for iamthwee

Nah, VS is too bloated and c++.net is horrible.

For pure c++. i.e no windows GUI crap, you don't need Visual Studio.

And anyway, if you are writing code it is best to test it with different compilers and operating systems to ensure portability.

ok what are you two arguing for. I have neither VC++ nor Bloodshed. BORLAND C++ is the best!!

ok what are you two arguing for. I have neither VC++ nor Bloodshed. BORLAND C++ is the best!!

hehehe i think you win :)

look up the sexually transmitted library (STL)

and the namspace std

along with vectors

very good read and you will learn much in doing so.

the standard template library introduces a lot of functionality.

http://www.sgi.com/tech/stl/stl_introduction.html

> BORLAND C++ is the best!!
'Created a game using C++ and OpenGL' is much better thing to write on your resume than 'Created a game using Borland C++'.

Member Avatar for iamthwee

>I have neither VC++ nor Bloodshed. BORLAND C++ is the best!!

That's because you are in a school being taught by clowns. :D

>I have neither VC++ nor Bloodshed. BORLAND C++ is the best!!

That's because you are in a school being taught by clowns. :D

You sure about that? Because you are arguing about compilers when the topic posted is What are vectors?

So whos being kiddish?

Member Avatar for iamthwee

> You sure about that? Because you are arguing about compilers when the topic posted is What are vectors?

Borland, Visual studio and dev-cpp are not compilers.

:D

And the argument is relevant because a lot of the code you write in the crusty old turbo c will not support what is standard c++. That may include std::vectors.

:D

you can't even understand what I meant by compilers and besides since I am just learning vectors I wouldn't start of with std::vectors.

I mean I will just start with declaring vectors and accessing vector member that's it, and I am sure that turbo c++ would support that.

Who told you I am using turbo c++ ? I am using borland C++ 5.5. And for your information that is not old.

So you are telling that arguing about whether to use dev c++ or VC++ has got everything to do with the topic WHAT ARE VECTORS?

If they are to you then I think you don't understand English.

So you are telling that arguing about whether to use dev c++ or VC++ has got everything to do with the topic WHAT ARE VECTORS?

If they are to you then I think you don't understand English.

Did you read the replies you got at the beginning of the thread? Your question was answered there - If you need a more detailed explanation than the one you recieved, then you need to ask a more specific question

The compiler discussion has been brought about by the fact that your ancient old Turbo C++ compiler doesn't support many modern C++ language features, vectors likely being one of these features.

Did you read the replies you got at the beginning of the thread? Your question was answered there - If you need a more detailed explanation than the one you recieved, then you need to ask a more specific question

The compiler discussion has been brought about by the fact that your ancient old Turbo C++ compiler doesn't support many modern C++ language features, vectors likely being one of these features.

Never in this topic have I mentioned that I use Turbo C++. Please read the topic fully before posting!

Thank you

iamthwee advised me to use devC++ that's it.

Member Avatar for iamthwee

Please calm down :)

Since Turbo C++ is a borland compiler the two can be mistaken. (old 'n' new) Just make sure you clarify next time.

int main()
{
    ////////////////////////////////////
    //
    //Fun With Vectors
    //
    ////////////////////////////////////
    //creating vectors
    //vectors are created like so
    //vector< datatype > variable name(size)
    //if the size is not included a vector of zero elements is created
    //an int vector with size defined
    vector<int> vec1(10);
    //an int vector without size defined
    vector<int> vec2;
    //adding elements to vector with size defined
    vec1.at(0) = 5;             //vector size is 10 (0-9)
    vec1[1] = 10;               //vector size is 10 (0-9)
    vec1.push_back(20);         //new vector size is 11 (0-10)
    /*
        quick break to note the above statement
        ---------------------------------------
        the size changed because push_back can be used to add elements
        to the end of the vector.  Thus causing the vectors size to change
    */
 
    //adding elements to a vector without size defined
    vec2.push_back(4);          //vector size is now 1 
    vec2.push_back(10);         //vector size is now 2 (0-1)
    vec2.at(1) = 10;            //vector size is still 2 but i have modified position 1 of the vector
    vec2[0] = 10                //vector size is still 2 but i have modified position 0 of the vector
    /*
        quick break to note the above statement
        ---------------------------------------
        the at() method can only be used on a vector after it has been given
        some data.  If not it will throw an error because the vector and has a size of 0
    */
    //resizing already sized vector
    vec1.resize(20);        //data within the vector is preserved
    //resizing vector with no initial size
    vec2.resize(15);        //data within the vector is preserved
    //itterating through a vector using while
    vector<int>::iterator vec1walk = vec1.begin();
    while (vec1walk != vec1.end())
    {
        //your code here
        vec1walk++;
    }
    //using for statement
    for (vector<int>::iterator vec2walk = vec2.begin(); vec2walk != vec2.end(); vec2walk++)
    {
        //your code here
    }
    //remove an element from the end of either
    vec1.pop_back();    //new vector size is 19 (0-18)
    vec2.pop_back();    //new vector size is 14 (0-13)
    //swap the elements of the two vectors
    vec1.swap(vec2);
    /*
        quick break to note the above statement
        ---------------------------------------
        the swap method will completely swap the two vectors
        this means that vec1 will now be 15 elements in length (0-14) containing all of the information from vec2
        this also means that vec2 will now be 20 elements in length (0-19) containing all of the information from vec1
    */
    //and this concludes our little look at vectors cheers!
}

Nah, VS is too bloated and c++.net is horrible.

For pure c++. i.e no windows GUI crap, you don't need Visual Studio.

And anyway, if you are writing code it is best to test it with different compilers and operating systems to ensure portability.

Even if you write a "Hello World" program VS spews out a massive array of files. That stuff SCARES me! Besides there are lots of open source gui
stuff out there (as I am discovering). Qt4,Glade, wxWidgets, Ogre,OpenGL
and there's this new guy o the block-OMGUI which is a modern version of wxWidgets which supports C++ classes.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.