c++ - Searching for an int inside a file -


so supposed take ints in source3.txt , check of them occur in source.txt. if of them don't occur, i'm supposed print corresponding line source2.txt output.txt (source2.txt contains descriptions of numbers in source 3, in same order, each description 1 line). wrote code, prints last line source2.txt, furthermore wrong line. have no idea might wrong. can me?

#include <bits/stdc++.h> using namespace std; int main() {     ifstream source ("source.txt");     ifstream source2 ("source2.txt");     ifstream source3 ("source3.txt");     vector<int> tab(1051,0);     vector<string> tab2(857,*new string);     vector<int> tab3(857,0);      ofstream output("output.txt");     for(int i=0;i<1050;++i)     {         source>>tab[i];     }     for(int i=0;i<856;++i)     {         string a;         getline(source2,a);         tab2[i]=a;         source3>>tab3[i];     }     for(int i=0;i<856;++i)     {         if(std::find(tab.begin(), tab.end(), tab3[i]) != tab.end())         {             continue;         }         else         {             output<<tab2[i]<<endl;         }     } } 

i think below modifications code should work . replace value of source_count 1051 , source2_count 857

#include <iostream> #include <fstream> #include <vector> #include <vector>  const int source_count = 4; const int source2_count = 3; //const int source2_count = 3;  using namespace std; int main() {     ifstream source ("source.txt");     ifstream source2 ("source2.txt");     ifstream source3 ("source3.txt");     vector<int> tab(source_count,0);     vector<string> tab2(source2_count,"");     vector<int> tab3(source2_count,0);      ofstream output("output.txt");     for(int i=0;i<source_count;++i)     {         source>>tab[i];     }     for(int i=0;i<source2_count;++i)     {         string a;         getline(source2,a);         tab2[i]=a;         source3>>tab3[i];     }     for(int i=0;i<source2_count;++i)     {         if(std::find(tab.begin(), tab.end(), tab3[i]) != tab.end())         {             continue;         }         else         {             output<<tab2[i]<<endl;         }     } } 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -