Iterating through a map that contains a vector

This is a discussion on Iterating through a map that contains a vector within the C++ Programming forums, part of the General Programming Boards category; Hi, I'm current trying to iterate through a map, which has a vector in its second field, but am getting ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    11

    Iterating through a map that contains a vector

    Hi, I'm current trying to iterate through a map, which has a vector in its second field, but am getting an error :

    Error 1 error C2440: 'initializing' : cannot convert from 'std::_Vector_iterator<_Ty,_Alloc>' to 'std::_Tree<_Traits>::iterator' h:\cosc208\ass2finalversion\ass2finalversion\corre lator2.cpp 70

    This is the code I've got so far:

    Code:
    for (std::map<std::string, std::vector<double>>::iterator iter4=metricNames.begin(); iter4!=metricNames.end(); ++iter4) {
    }
    Any help much appreciated, thanks

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,538
    How does metricNames look like?
    And btw,
    std::map<std::string, std::vector<double>>
    This is illegal C++. It's a Microsoft C++ extension. Don't do it.
    All the ">" in templates must be separated. So you must do:
    std::map<std::string, std::vector<double> >
    Or
    std::map< std::string, std::vector<double> >
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    11
    Thanks for the tip re: >> . I think I have sorted it now, I hadn't declared metricNames properly!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Polynomials and ADT's
    By Emeighty in forum C++ Programming
    Replies: 20
    Last Post: 08-19-2008, 08:32 AM
  2. can some one please tell me the cause of the error ?
    By broli86 in forum C Programming
    Replies: 8
    Last Post: 06-26-2008, 08:36 PM
  3. syntax help?
    By scoobygoo in forum C++ Programming
    Replies: 1
    Last Post: 08-07-2007, 10:38 AM
  4. Need some help/advise for Public/Private classes
    By nirali35 in forum C++ Programming
    Replies: 8
    Last Post: 09-23-2006, 12:34 PM
  5. Certain functions
    By Lurker in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2003, 12:26 AM

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