need help with std::set::iterator

This is a discussion on need help with std::set::iterator within the C++ Programming forums, part of the General Programming Boards category; Okay, what I have is a std::set< string > defined that holds a group of strings (unknown mathematical variables) that ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    110

    need help with std::set::iterator

    Okay, what I have is a std::set< string > defined that holds a group of strings (unknown mathematical variables) that are the different names of the columns in a matrix.
    What I need to do is after finding an occurance of a variable in an equation is store it in the appropriate place in the matrix.
    What I am currently doing is
    Code:
      set< string >::iterator variablePos = variables.find( variableString );
    but I am at a dead end in the fact that I have no idea how to get the position of the iterator, is it as simple as
    Code:
      variablePos.position();
    or is there something that I am completely missing (have not done much work with c++ iterators before).

    Also, am I going about this the best way or is there some really easy function that will do it all for me.

    Thanks,
    WebmasterMattD
    WebmasterMattD.NET

  2. #2
    Veni Vidi Vice
    Join Date
    Aug 2001
    Posts
    343
    Find returns an iterator

    If you want to se what address the variable variablePos has
    Code:
    cout << &variablePos;
    To get the address that variablePos is pointing to
    Code:
    cout << variablePos;
    To get the element that variablePos is pointing to
    Code:
    cout << *variablePos;
    Also you should make a check on variablePos to se if the find member function actually found something
    Code:
    if (variablePos !=variables.end())
    //Match
    else
    //No match
    Use this page as a reference
    01000111011011110110111101100100 011101000110100001101001011011100110011101110011 01100100011011110110111001110100 01100011011011110110110101100101 01100101011000010111100101110011 0110100101101110 01101100011010010110011001100101
    Good things donīt come easy in life!!!

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21