c++ - invalid operands to binary expression ('std::__1::basic_ostream<char>' and 'ostream' (aka 'basic_ostream<char>')) std::cout<<check<<std::cout; -
i'm trying solve standard interview question. i've vector each element vector of ints. v[0] employee 0 , vector of ints in v[0] number of employees reporting him, 2,3,5. if v[2] has 7 indirectly 7 reports employee 0 through 2. question find function takes in 2 ints , b , vector of dependencies , if reports b, directly or indirectly.
here's bfs logic
bool dependencylist(int a, int b, std::vector<std::vector<int>>& v){ std::queue<int> q; std::vector<int> d; std::unordered_map<int, int> m; for(auto = v[b].begin(); it!= v[b].end(); it++){ q.push(*it); d.push_back(*it); m[*it] = 1; } while(!q.empty()){ int num = q.front(); for(auto = v[num].begin(); != v[num].end(); it++){ if(m.find(*it) == m.end()){ d.push_back(*it); m[*it] =1; q.push(*it); } } q.pop(); } for(auto it= d.begin(); it!= d.end(); it++){ if(*it == a) return true; } return false; }
here's driver code
int main() { std::vector<int> v0; v0.push_back(2); v0.push_back(3); v0.push_back(7); std::vector<int> v1; v1.push_back(4); v1.push_back(9); v1.push_back(11); std::vector<int> v2; v2.push_back(3); v2.push_back(5); std::vector<int> v3; v3.push_back(8); v3.push_back(6); std::vector<std::vector<int>> v; v.push_back(v0); v.push_back(v1); v.push_back(v2); v.push_back(v3); bool check = dependencylist(6,0,v); std::cout<<check<<std::cout; return 0; }
here's error get
invalid operands binary expression ('std::__1::basic_ostream<char>' , 'ostream' (aka 'basic_ostream<char>')) std::cout<<check<<std::cout; ~~~~~~~~~~~~~~~~^ ~~~~~~~~~
try removing std::cout;
expression std::cout<<check<<std::cout;
if compile code using gnu g++ compiler, compiles fine. if compile using visual c++ compiler (c++11 tested with) gives error.
with g++ compiler displays address of object std::cout
. if want display address, try std::cout<<check<<&std::cout;
Comments
Post a Comment