0

problem with my code

Find matching numbers in text files file1.txt and file2.txt and write them to a new text file result.txt. In each of the source files, the numbers are not repeated. the code i tried #include<iostream> #include<fstream> #include<iomanip> #include<numeric> #include<math.h> using namespace std; int main(){ int i, n1,n2; int tab1[20]{}; int tab2[20]{}; int compare = 0; fstream f1; f1.open("c:\\Temp\\file1.txt",ios::in); fstream f2; f2.open("c:\\Temp\\file2.txt",ios::in); fstream f3; f3.open("c:\\Temp\\result.txt",ios::out|ios::trunc); bool flag = false; if(f1 && f2 && f3){ while(!f1.eof()&& !f2.eof()){ f1>>n1; f2>>n2; cout<<endl<<n1<<" "<<n2<<" "; } bool arraysEgaux=false; do{ cin>>tab1[i]; for(int j = 0; j < n2; j++){ if(tab1[i]==tab2[j]){ arraysEgaux=true; break; cout<<tab1[i]<<" "; f3<<tab1[i]<<" "; i++; } } }while (i<20); } f1.close(); f2.close(); f3.close(); } cout<<"ERROR "<<endl; //system("pause"); //return 0;

8th Apr 2022, 12:23 PM
ARONA
ARONA - avatar
2 Answers
0
Hi, welcome, I am not here to post an answer (I don't know the answer), but I know that people wish to see this code saved as a code playground file: click { } at the bottom of your page, click +new code, choose your language, write your code and save it, and then edit your question to insert code, choose "my code bits", choose this code file, click done, write as tags the language and some helpful keywords of your choosing, then save your edit. I guess you've just become SL'er, so, this is what people do. Also, we're expected to let people know if our question's got a reply that answers the question. [Solved] is edited in the left hand side of the question title for this purpose. Have a nice day :-)
11th Apr 2022, 8:56 PM
Korkunç el Gato
Korkunç el Gato - avatar
0
Hi, I'm new and all, but I know some stuff. This code is way too undefined and explained. I believe that you need to recheck everything, but perhaps you haven't shown the rest of the code... Please do, so that I or the community can help out. Besides this, I really don't know what you're trying to do. Just search on Google, or ask a professional. Your friend, None of Your Business (NYB)
11th Apr 2022, 8:56 PM
NYB
NYB - avatar