How do I get the value of a pointer?

I've been working on some project code and the project is basically to read in a file that has contacts in it, put the data into nodes, put those nodes into a list, remove the duplicates and then print out the list. I have done this.

Now, I need to get all the duplicates that were removed and output them (Like, "The contacts that were deleted are: " )

I don't really know where to start. Anytime I run it, it prints out the address (it prints something like 0xf9000).

I would appreciate some guidance or help. Here's where I'm trying to implement it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  void purge(List &L){
    //ElementType fir, midd, las, phon;
//List R;
vector<NodePointer> duplic;
NodePointer p, q, pQ;
int counter = 0;
p = L.getFirst();

 while(p != nullptr){
  q = p->getNext();
    while( q != nullptr){
      if(p->sameAs(q) == true){
        counter++;
        pQ = q;
        q = q->getNext();
//The vector duplic is my attempt to push the value into the vector so I can print it out
      duplic.push_back(pQ);
        L.remove(pQ);
      }
      else
        q = q->getNext();
    }
  p = p->getNext();
  }
  cout << "The number of deleted duplicates are: " << counter << endl;
  for(int i = 0; i < duplic.size(); i++){
    cout << duplic.at(i);
    cout <<endl;
  }
}
Last edited on
Well going from your previous posts, perhaps
1
2
3
4
  for(int i = 0; i < duplic.size(); i++){
    cout << duplic.at(i)->printNode();
    cout <<endl;
  }


> typedef Node* NodePointer;
This more often than not only serves to obscure things rather than inform.
Like not being reminded that the thing you have is really a pointer, and that you need to dereference it to get anywhere.

When I do that I get a compiler error that says "no match for 'operator <<' (operand types are std::ostream {aka std::basic_ostream}' and 'void')
Last edited on
salem just made a mistake. It should be
 
  duplic.at(i)->printnode();    // get rid of the cout << 

I get a bunch of scrambled looking letters as my output. It looks like:

http://prntscr.com/rvmpa1

What does the Node::printNode() do?
What does the List::remove(Node*) do?
Okay, I got it. I used my printNode() function in the loop before it removed the node. Thank you all for your help.
Topic archived. No new replies allowed.