problem with c++ find, find_if


 
Thread Tools Search this Thread
Top Forums Programming problem with c++ find, find_if
# 1  
Old 12-06-2011
problem with c++ find, find_if

I am trying to search a vector for something, and it I find it, do something.

I have this so far,
Code:
vector<vector<int> >::iterator path_iterator;
vector<int>::iterator path_iterator;
vector<int> check_path;

   // to each path1[i], try to add a neighbor of last_vertex
   for(j=0; j<last_vertex_delta; j++) {
      current_neighbor = vertex_list[last_vertex_in_path].neighbor_nums[j];

      // copy from vec<vec<int>> to temp vec, probably not necessary
      check_path = new_set_of_paths[path_count];

      // search path to see if current_neighbor is already part of path
      path_iterator = find_if(check_path.begin(),
                              check_path.end(),
                              current_neighbor);

      cout << "last_atom_in_path " << last_atom_in_path << endl;
      cout << "current_neighbor " << current_neighbor << endl;
      cout << "path_iterator " << * path_iterator << endl;
      cout << endl;

      // if the neighbor isn't already part of the path, add it
      if(path_iterator == check_path.end()) {
         new_set_of_paths[path_count].push_back( current_neighbor );
         path_count ++;
      }

      check_path.clear();
   }

The if(path_iterator == check_path.end()) line isn't kosher. If I remember how find_if works, you send the third argument to a function that returns a bool and find_if returns the first value where the bool function returns true. True in this context would mean that the value is already in the vector, so it seems like the bool function has to do the heavy lifting here. I'm not sure what the bool function should look like and why I can just use find and have it return an iterator to the position of anything that matches current_neighbor.

I tried that,
Code:
      path_iterator = find(check_path.begin(),
                           check_path.end(),
                           current_neighbor);

      cout << "last_atom_in_path " << last_atom_in_path << endl;
      cout << "current_neighbor " << current_neighbor << endl;
      cout << "path_iterator " << * path_iterator << endl;
      cout << endl;

      // if the neighbor isn't alreay part of the path, add it
      if(path_iterator == 0) {
         new_set_of_paths[path_count].push_back( current_neighbor );
         path_count ++;
      }

but this doesn't work either. If I print *path_iterator, it prints as 0 when the vertex isn't found in the vector, but I can't seem to evaluate the iterator that way.

Any suggestions as to what I have wrong here?

LMHmedchem
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem with find

Hello, I have trouble using the find command (I am working on Mac OSX). for i in *.pdf do if find . -name "EV" then mv "$i" E-test.pdf elif find . -name "GV" then mv "$i" G-test.pdf else mv "$i" test.pdf fi done As to the use of "$i": unfortunately, the filenames... (14 Replies)
Discussion started by: tempestas
14 Replies

2. Shell Programming and Scripting

Problem with find command "find: cannot open"

Hello Guys , I am trying to run below find command in one of my SH script on a HP UX machine. find /tmp -type f -name "MGCA*.log" -prune -exec rm -f {} \; 2>&1 I want this to check my tmp directory and delete MGCA log files .But below error message is printed on Promt :- find: cannot... (2 Replies)
Discussion started by: himanshu sood
2 Replies

3. Shell Programming and Scripting

find problem

Hi I want to find files with size +10000M and specified directorys except when i use more than one `-name` acton is fail I try -a (and) and -o (-or) but results fail :( find . \( -name ./oracle* -prune -o -name "*arc*" -prune -o -name "*oracle*" -prune -o -size +10000k \) -exec ls -lh {}... (7 Replies)
Discussion started by: ygemici
7 Replies

4. Shell Programming and Scripting

find problem

for index in `find /root -name *.jar | grep "/lib"`; do echo "$index"; done sometimes its throwing error saying find: paths must precede expression Usage: find some1 suggested me that : Code: for index in `find /technologies -name '*.jar' | grep "/lib"` do echo "$index"... (2 Replies)
Discussion started by: crackthehit007
2 Replies

5. Shell Programming and Scripting

Problem with find command.

I'm trying to display the full file name (including the full path) and file size of all files whose name (excluding the path) is longer than 10 characters. I came up with find path -type f -name ".{10, }" -printf "%s %p\n", but I'm getting a "find: path: No such file or directory". What's wrong... (2 Replies)
Discussion started by: raidkridley
2 Replies

6. Shell Programming and Scripting

Find command problem

Hi All, I am using following find command to delete the records older than 7 days but getting missing conjuction error.Kindly suggest: The command is: find <complete_dir_path> \(! -name usr -prune \) -type f -name "*.txt" -mtime +6 -print | xargs rm (11 Replies)
Discussion started by: visingha
11 Replies

7. UNIX for Dummies Questions & Answers

FIND/GREP problem

When I enter the command below grep appears to be returning a file it shouldn't. find . -name "*.*" -exec grep "testing" {} /dev/null \; .:ops3Mailfile ./SSI.ksh: # create TECHOUT dummy for test for testing purposes ./ftprimi1.ksh:# before running job in prod... change FTP to... (1 Reply)
Discussion started by: dfb500
1 Replies

8. Shell Programming and Scripting

problem with find

Hi, Iam having a strange problem, wandering if soneone can throw some lights. I have statement find . -maxdepth 1 -name 'File1*.tsv' -mtime +1 -print I expect the above statement to print the files older than 1 day or 24 hrs, however it doesn't work that way. When issue above command,... (2 Replies)
Discussion started by: braindrain
2 Replies

9. Shell Programming and Scripting

Problem with `find ...`

Hi all, Have the following snippet of code that I'm having trouble trying to work ... The snippet of code is running on our Production Server and the intent is to copy the second most recent IDE file across from the Development Server. I have the following files defined in $DEVLOC ...... (4 Replies)
Discussion started by: Cameron
4 Replies

10. Shell Programming and Scripting

Another Find Problem

HI All, I am having a bit of trouble using the find command in my shell (korn) script. I was hoping someone could help me. I am trying to build up a dynamic find command based on some parameters. When I execute the command I get the following error: find: incomplete statement I have... (6 Replies)
Discussion started by: sethkor
6 Replies
Login or Register to Ask a Question