[C++] Can i learn vector before arrays

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

43 Replies - 2233 Views - Last Post: 08 January 2014 - 05:42 PM Rate Topic: -----

#1 Nathan2222   User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 100
  • Joined: 01-January 14

[C++] Can i learn vector before arrays

Posted 07 January 2014 - 01:42 PM

The c++ tutorial i'm using teaches vector first and arrays comes much much later. I don't understand the vector code.
Is This A Good Question/Topic? 0
  • +

Replies To: [C++] Can i learn vector before arrays

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15686
  • View blog
  • Posts: 62,831
  • Joined: 12-June 08

Re: [C++] Can i learn vector before arrays

Posted 07 January 2014 - 01:43 PM

Sure.. I would imagine you can learn one before the other. If that is confusing why not read the chapter on arrays first then page back to vectors?
Was This Post Helpful? 0
  • +
  • -

#3 jimblumberg   User is offline

  • member icon

Reputation: 5836
  • View blog
  • Posts: 17,794
  • Joined: 25-December 09

Re: [C++] Can i learn vector before arrays

Posted 07 January 2014 - 01:53 PM

Perhaps you need to find a different tutorial, but yes you can learn vectors before/instead of arrays.

Jim
Was This Post Helpful? 0
  • +
  • -

#4 Nathan2222   User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 100
  • Joined: 01-January 14

Re: [C++] Can i learn vector before arrays

Posted 07 January 2014 - 01:59 PM

View Postmodi123_1, on 07 January 2014 - 01:43 PM, said:

Sure.. I would imagine you can learn one before the other. If that is confusing why not read the chapter on arrays first then page back to vectors?

I tried doing that but the array code used the vector code example and other things that were taught in the 10+ chapters leading to arrays.
Was This Post Helpful? 0
  • +
  • -

#5 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15686
  • View blog
  • Posts: 62,831
  • Joined: 12-June 08

Re: [C++] Can i learn vector before arrays

Posted 07 January 2014 - 02:01 PM

Okay dokey.. so then find an alternative place of study for arrays and vectors. ... or if this book is taking you through honest to goodness vectors then perhaps reread it. The author had a plane for this path of study.

ex:
http://www.cplusplus.../vector/vector/
Was This Post Helpful? 0
  • +
  • -

#6 Nathan2222   User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 100
  • Joined: 01-January 14

Re: [C++] Can i learn vector before arrays

Posted 07 January 2014 - 02:02 PM

View Postmodi123_1, on 07 January 2014 - 01:43 PM, said:

Sure.. I would imagine you can learn one before the other. If that is confusing why not read the chapter on arrays first then page back to vectors?

I tried doing that but the array code used the vector code example and other things that were taught in the 10+ chapters leading to arrays.
Was This Post Helpful? 0
  • +
  • -

#7 Nathan2222   User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 100
  • Joined: 01-January 14

Re: [C++] Can i learn vector before arrays

Posted 07 January 2014 - 02:22 PM

Sorry for double post.

The author is the creator of the language and he probably had a reason for doing that.

Here is the code:
[code]//simple dictionary: list of sorted words
int main()
{
vector<string>words;
string temp;
while(cin>>temp)
words.push_back(temp);

cout<<"Number of words: " <<words.size()<<endl;
 
sort(words.begin(),words.end());

for(int i = 0; i < words.size(); ++i)
if (i == 0 || words[i-1]!=words[i])
cout <<words[i]<<"\n";
}

This post has been edited by jimblumberg: 07 January 2014 - 02:24 PM
Reason for edit:: Fixed code tags.

Was This Post Helpful? 0
  • +
  • -

#8 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15686
  • View blog
  • Posts: 62,831
  • Joined: 12-June 08

Re: [C++] Can i learn vector before arrays

Posted 07 January 2014 - 02:25 PM

... the author created c++? Hmm. That conflicts with prior creationist histories.


Quote

Here is the code:

... okay?
Was This Post Helpful? 0
  • +
  • -

#9 jimblumberg   User is offline

  • member icon

Reputation: 5836
  • View blog
  • Posts: 17,794
  • Joined: 25-December 09

Re: [C++] Can i learn vector before arrays

Posted 07 January 2014 - 02:26 PM

So what exactly don't you understand?

By the way you need to find an indentation style you like and use it consistently, it'll make reading your code much easier.

Jim
Was This Post Helpful? 0
  • +
  • -

#10 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6259
  • View blog
  • Posts: 24,028
  • Joined: 23-August 08

Re: [C++] Can i learn vector before arrays

Posted 07 January 2014 - 02:27 PM

Can you provide a link to this tutorial?
Was This Post Helpful? 0
  • +
  • -

#11 Nathan2222   User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 100
  • Joined: 01-January 14

Re: [C++] Can i learn vector before arrays

Posted 07 January 2014 - 02:34 PM

View Postjimblumberg, on 07 January 2014 - 02:26 PM, said:

So what exactly don't you understand?

By the way you need to find an indentation style you like and use it consistently, it'll make reading your code much easier.

Jim

It's hard to indent when you are posting with a phone.
I don't understand why there is a for loop, why it is 'cout<<words[i]' not 'cout<<words'. What purpose 'i' serves in the code. And that 'if' code.

The tutorial is in the programming principles book

This post has been edited by Nathan2222: 07 January 2014 - 02:36 PM

Was This Post Helpful? 0
  • +
  • -

#12 jimblumberg   User is offline

  • member icon

Reputation: 5836
  • View blog
  • Posts: 17,794
  • Joined: 25-December 09

Re: [C++] Can i learn vector before arrays

Posted 07 January 2014 - 02:35 PM

The for loop is there to print out all of the words. Remember words is a vector<string> which means that there are multiple words in the container.

Jim
Was This Post Helpful? 0
  • +
  • -

#13 Nathan2222   User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 100
  • Joined: 01-January 14

Re: [C++] Can i learn vector before arrays

Posted 07 January 2014 - 02:53 PM

View Postjimblumberg, on 07 January 2014 - 02:35 PM, said:

The for loop is there to print out all of the words. Remember words is a vector<string> which means that there are multiple words in the container.

Jim

Aren't loops used to do an action multiple times. Isn't cout for output. What purpose does 'i' serve.

View Postjimblumberg, on 07 January 2014 - 02:35 PM, said:

The for loop is there to print out all of the words. Remember words is a vector<string> which means that there are multiple words in the container.

Jim

Aren't loops used to do an action multiple times. Isn't cout for output. What purpose does 'i' serve.
Was This Post Helpful? 0
  • +
  • -

#14 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15686
  • View blog
  • Posts: 62,831
  • Joined: 12-June 08

Re: [C++] Can i learn vector before arrays

Posted 07 January 2014 - 02:58 PM

I do believe 'printing to screen' is an action.

The 'i' is a loop control variable. The variable to help keep the proper step in the loop. I would suggest rereading loops and their conditions.
Was This Post Helpful? 0
  • +
  • -

#15 Nathan2222   User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 100
  • Joined: 01-January 14

Re: [C++] Can i learn vector before arrays

Posted 07 January 2014 - 03:22 PM

View Postmodi123_1, on 07 January 2014 - 02:58 PM, said:

I do believe 'printing to screen' is an action.

The 'i' is a loop control variable. The variable to help keep the proper step in the loop. I would suggest rereading loops and their conditions.

so what is getting looped. Why is it words[i] not words.

This post has been edited by Nathan2222: 07 January 2014 - 03:23 PM

Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3