[ create a new paste ] login | about

Link: http://codepad.org/rcxrAksD    [ raw code | output | fork ]

C++, pasted on Feb 24:
#include "assert.h"
#include "string.h"
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int check_for_double(vector<string> * vocabulary){
  vector<string> :: iterator temp;
  int counter1=0;
  int counter2=0;
  for(vector<string> :: iterator i=vocabulary->begin();i!=vocabulary->end();i++ ){
    cout<<"                             outer loop: "<<endl<<
      "                                counter: "<<counter1<<endl<<
      "                                value: "<< *i<<endl;
    for(vector<string> :: iterator j=vocabulary->begin();j!=vocabulary->end();++j){
      cout<<"inner loop\n";
      cout<<"counter: "<<counter2<<endl<<
      "value: "<< *j<<endl;
      if((*i)==(*j)&&i!=j){
	temp=j-1;
	cout<<"erase occured**************************************8\n";
	vocabulary->erase(j);
	j=temp;
	
	
      }
      counter2++;
    }
    cout<<"got out from inner loop\n";
    counter1++;
    counter2=0;

  }
  return 1;
}
void check_for_double_test(){
  vector<string>  x;
  x.push_back("hello");
  x.push_back("hello");
  x.push_back("world");
  x.push_back("this");
  x.push_back("this");
  x.push_back("is");
  x.push_back("jenia");
  x.push_back("jenia");
  check_for_double(&x);
  assert(x[0]=="hello");
  assert(x[1]=="world");
  assert(x[2]=="this");
  assert(x[3]=="is");
  assert(x[4]=="jenia");
}
  
int main(){
  //substring_test();
  check_for_double_test();

}
//this gives me segmentation fault right at the end.
//how can i solve this problem


Output:
                             outer loop: 
                                counter: 0
                                value: hello
inner loop
counter: 0
value: hello
inner loop
counter: 1
value: hello
erase occured**************************************8
inner loop
counter: 2
value: world
inner loop
counter: 3
value: this
inner loop
counter: 4
value: this
inner loop
counter: 5
value: is
inner loop
counter: 6
value: jenia
inner loop
counter: 7
value: jenia
got out from inner loop
                             outer loop: 
                                counter: 1
                                value: world
inner loop
counter: 0
value: hello
inner loop
counter: 1
value: world
inner loop
counter: 2
value: this
inner loop
counter: 3
value: this
inner loop
counter: 4
value: is
inner loop
counter: 5
value: jenia
inner loop
counter: 6
value: jenia
got out from inner loop
                             outer loop: 
                                counter: 2
                                value: this
inner loop
counter: 0
value: hello
inner loop
counter: 1
value: world
inner loop
counter: 2
value: this
inner loop
counter: 3
value: this
erase occured**************************************8
inner loop
counter: 4
value: is
inner loop
counter: 5
value: jenia
inner loop
counter: 6
value: jenia
got out from inner loop
                             outer loop: 
                                counter: 3
                                value: is
inner loop
counter: 0
value: hello
inner loop
counter: 1
value: world
inner loop
counter: 2
value: this
inner loop
counter: 3
value: is
inner loop
counter: 4
value: jenia
inner loop
counter: 5
value: jenia
got out from inner loop
                             outer loop: 
                                counter: 4
                                value: jenia
inner loop
counter: 0
value: hello
inner loop
counter: 1
value: world
inner loop
counter: 2
value: this
inner loop
counter: 3
value: is
inner loop
counter: 4
value: jenia
inner loop
counter: 5
value: jenia
erase occured**************************************8
got out from inner loop


Create a new paste based on this one


Comments: