deleting an elements

hello guys ...

Here I have a problem to code my algorithm...

I have a list of numbers that save in text file format. And the list is as follow :

1 2 3 4 5 6 7 8 9

And another list that also save in text file format . and here is the list :
2 4 6

What I want to do is, I would like to compare the elements in text 1 and text 2, and if the numbers in text 1 exist in text 2, i don't want that numbers. so the resultshould be like this ...

1 3 5 7 8 9

i have tried code it but my program cannot give th result as i want.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include<iostream>
#include<fstream>

using namespace std;

void main()
{
ifstream infile1;
infile1.open("text1.txt");

ifstream infile2;
infile2.open("text2.txt");

int no1,no2,*a,*b;
infile1 >> no1;
infile2 >> no2;

a = new int[no1];
b = new int[no2];

for(int i=0;i<n01;i++)
infile1 >> a[i];

for(int j=0;j<no2;j++)
infile2 >> b[i];

for(int i=0;i<no1;i++)
{
     for(int j=0;j<no2;j++)
     {
       if(a[i] != b[j])
       {
         cout << a[i] << endl;
       }
     }
}

}


i hope anyone here can help me...

Thank you very much...
:)
1
2
3
4
5
int a[9] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; //assume this array of int is from text1
int b[3] = {2, 4, 6}; //assume this array of int is from text2
vector<int> vecRes;
set_difference(a,a+9,b,b+3,back_inserter(vecRes));
copy(vecRes.begin(),vecRes.end(),ostream_iterator<int>(cout,"\n"));


Write your code to populate a and b array variables.

sir, thanks for response , but i need more explanation coz i could not understand .

tyvm sir..
vector, set_difference, copy are all containers and functions from the Standard C++ STL library.

Refer to http://www.cplusplus.com/reference/stl/
ahaa...thanks alot ...
Topic archived. No new replies allowed.