Last week I was goofing around with multidimensional vectors and removing an element from each row. I got my code to remove and element from each row working inside int main, but when I put all this code inside of a function I started to get errors. The common error that I am getting is

main.cpp:83: error: conversion from ‘__gnu_cxx::__normal_iterator<std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >*, std::vector<std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, std::allocator<std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > > >’ to non-scalar type ‘__gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >’ requested
main.cpp:84: error: no match for ‘operator<’ in ‘ITx < ((std::vector<std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, std::allocator<std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >*)Mat)->std::vector<_Tp, _Alloc>::end [with _Tp = std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, _Alloc = std::allocator<std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >]()’

not really sure why I am getting this error. Not that great with pointers and kind of understand them to a point for a non computer sci major. Why would I be getting this error and how can I correct it. Below is my code

#include <iostream>
#include <string>
#include <vector>


void removeElement(std::vector<std::vector<std::string> > &Mat, std::string El);

int main() {

    std::vector<std::vector<std::string> > voteMat;
    std::vector<std::string> chairRank;

    std::string temp;

    int NC,NV;
    // NC -> number of candidates
    // NV -> number of voters 

    std::cin >> NV >> NC;

    // Parse in the chairman's ranking vector
    for(unsigned x=0; x<4 && !std::cin.eof(); ++x) {
        std::cin >> temp;
        chairRank.push_back(temp);
    }

    // Parse in the Voters Ranking vectors into the matrix
    for(int x=0; x<NV && !std::cin.eof(); ++x) {
        std::vector<std::string> row;
        for(int y=0; y<NC; ++y) {
            std::cin >> temp;
            row.push_back(temp);
        }
        voteMat.push_back(row);
        row.clear();
    }

    std::cout << "Done parsing input\n\n";

    std::cout << "Voter's Matrix\n\n";

    // Print the voters ranking matrix
    std::vector<std::vector<std::string> >::iterator ITx = voteMat.begin();
    for(; ITx<voteMat.end(); ++ITx) {
        std::vector<std::string>::iterator ITy = ITx->begin();
        for(; ITy<ITx->end(); ++ITy) {
            std::cout << *ITy << " ";
        }
        std::cout << std::endl;
    }
    std::cout << std::endl;
    std::cout << "Removing Chicago from Matrix\n\n";

    // Remove Chicago from each row vector in the matrix
//    ITx = voteMat.begin();
//    for(; ITx<voteMat.end(); ++ITx) {
//        std::vector<std::string>::iterator ITy = ITx->begin();
//        for(; ITy<ITx->end(); ++ITy) {
//            if(*ITy == "chicago") {
//                ITx->erase(ITy);
//            }
//        }
//    }

    removeElement(voteMat,"chicago");

    // Print the voters ranking matrix
    std::cout << "Printing Matrix without Chicago\n";
    ITx = voteMat.begin();
    for(; ITx<voteMat.end(); ++ITx) {
        std::vector<std::string>::iterator ITy = ITx->begin();
        for(; ITy<ITx->end(); ++ITy) {
            std::cout << *ITy << " ";
        }
        std::cout << std::endl;
    }
    std::cout << std::endl;

    return 0;
}

void removeElement(std::vector<std::vector<std::string> > &Mat, std::string El) {
    std::vector<std::string>::iterator ITx = Mat.begin();
    for(; ITx<Mat.end(); ++ITx) {
        std::vector<std::string>::iterator ITy = ITx->begin();
        for(; ITy<ITx->end(); ++ITy) {
            if(*ITy == El) {
                ITx->erase(ITy);
            }
        }
    }
}

this is the input I am using on the standard input "./a.out < input.txt"

8 4
madrid chicago rio tokyo
madrid chicago tokyo rio
chicago rio tokyo madrid
madrid rio tokyo chicago
rio tokyo chicago madrid
madrid rio tokyo chicago
tokyo rio chicago madrid
rio madrid tokyo chicago
rio tokyo chicago madrid

Edited 7 Years Ago by Talguy: n/a

line 83 is wrong

void removeElement(std::vector<std::vector<std::string> > &Mat, std::string El) {
    std::vector<std::vector<std::string> >::iterator  ITx = Mat.begin();
    for(; ITx<Mat.end(); ++ITx) {
        std::vector<std::string>::iterator ITy = ITx->begin();
        for(; ITy<ITx->end(); ++ITy) {
            if(*ITy == El) {
                ITx->erase(ITy);
            }
        }
    }
}
This article has been dead for over six months. Start a new discussion instead.