943,865 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 649
  • C++ RSS
Jul 4th, 2009
1

Help with a vector<vector<string> *>

Expand Post »
Hi, for a class, I'm trying to implement a separate-chaining hash table stored in a vector that contains pointers to vectors where the keys will be stored. This is basically what I have:

c++ Syntax (Toggle Plain Text)
  1. typedef vector<string> KeyChain;
  2. vector<KeyChain *> Table;

The problem I'm having is when I want to access the keys in the KeyChain, I don't know how to get to those values, this is what I've tried:
c++ Syntax (Toggle Plain Text)
  1. Table[value][index]
  2. Table[value]->[index]

What is the syntax for accessing the items in a vector that is referenced with a pointer in another vector? Thank you for your help!
Similar Threads
Reputation Points: 15
Solved Threads: 0
Newbie Poster
squall1986 is offline Offline
5 posts
since Jul 2009
Jul 4th, 2009
0

Re: Help with a vector<vector<string> *>

Welcome squall1986,

Use may use :
C++ Syntax (Toggle Plain Text)
  1. (*(Table[index]))[index];
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Jul 5th, 2009
0

Re: Help with a vector<vector<string> *>

Click to Expand / Collapse  Quote originally posted by adatapost ...
Welcome squall1986,

Use may use :
C++ Syntax (Toggle Plain Text)
  1. (*(Table[index]))[index];
Thank you, that works, but I also asked my instructor about it, and he told me that he wanted us to do something along these lines:

c++ Syntax (Toggle Plain Text)
  1. vector<string> *Table;
  2. Table = new vector<string>[size];

So I'll be doing that, but thanks for the help!
Reputation Points: 15
Solved Threads: 0
Newbie Poster
squall1986 is offline Offline
5 posts
since Jul 2009
Jul 5th, 2009
0

Re: Help with a vector<vector<string> *>

So, where is a problem?
C++ Syntax (Toggle Plain Text)
  1. vector<string> *Table;
  2. Table = new vector<string>[2];
  3.  
  4. Table[0].push_back("Aaa");
  5. Table[0].push_back("Bbb");
  6. Table[0].push_back("Ccc");
  7.  
  8. Table[1].push_back("Ppp");
  9. Table[1].push_back("Qqq");
  10.  
  11. cout << "\n" << Table[0][0];
  12. cout << "\n" << Table[0][1];
  13. cout << "\n" << Table[0][2];
  14. cout << "\n" << Table[1][0];
  15. cout << "\n" << Table[1][1];
  16. Table[0][0]="AAAAAA";
  17. ....
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Jul 5th, 2009
0

Re: Help with a vector<vector<string> *>

Click to Expand / Collapse  Quote originally posted by adatapost ...
So, where is a problem?
Umm ... I don't think there is a problem now, it's working fine for me. Are you asking me that because you see one and you want me to look for it ... ?
Reputation Points: 15
Solved Threads: 0
Newbie Poster
squall1986 is offline Offline
5 posts
since Jul 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: simple code not working
Next Thread in C++ Forum Timeline: Save function not working





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC