to resolve Core error.

After compiling and executing the exe, i get the below message.
Segmentation Fault (Core dumped).

Any ideas why this happen and how to resolve this.

find below the code.

-----
#include <string>
#include <fstream>
#include <vector>
using namespace std;

int main() {
  vector<string> tline ;
  vector<string> outf ;
  ifstream in("test.lst");
  string word,line;
  int found ;
  while(getline(in,line))
          {
                 tline.push_back(line) ;
                 for (int i=0; i<tline.size(); i++)
                         {
                         word = tline[i] ;
                    if ( word == "From" )
                                { found = 1 ; break ; }
          else
                           { found = 0 ; continue  ; }
                    }

                 if ( found == 0 )
                        outf.push_back(line);
                 else
                        {
                          tline.empty();
                          continue ;
                        }
          }
 for (int i=0;outf.size() ; i++ )
         cout << outf[i] << endl ;

}

-----
beginAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chensuCommented:
Debug it.
0
beginAuthor Commented:
points not applicable to chensu.
--begin
0
snifongCommented:
#include <string>
#include <fstream>
#include <vector>
#include <iostream>

using namespace std;

int main() {
  vector<string> tline ;
  vector<string> outf ;
  ifstream in("test.lst", ios::in | ios::binary);
  if (!in)
        cout << "error." << endl;
  string word,line;
  int found ;
  while(in >> line)
          {
                 tline.push_back(line) ;
                 for (int i=0; i<tline.size(); i++)
                         {
                         word = tline[i] ;
                    if ( word == "From" )
                                { found = 1 ; break ; }
          else
                           { found = 0 ; continue  ; }
                    }

                 if ( found == 0 )
                        outf.push_back(line);
                 else
                        {
                          tline.empty();
                          continue ;
                        }
          }
//This was the problem.  In yours you had "outf.size()" instead of "i < outf.size()"
 for (int i=0;i < outf.size() ; i++ )
         cout << outf[i] << endl ;
}

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
beginAuthor Commented:
snifog, thanks for solving the core error, but i could not proceed further, i get an output just "error".
--begin
0
snifongCommented:
Let me see the *.lst file that you are using.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.