[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

to resolve Core error.

Posted on 2000-01-05
5
Medium Priority
?
178 Views
Last Modified: 2010-04-01
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 ;

}

-----
0
Comment
Question by:begin
  • 2
  • 2
5 Comments
 
LVL 23

Expert Comment

by:chensu
ID: 2328116
Debug it.
0
 

Author Comment

by:begin
ID: 2328192
points not applicable to chensu.
--begin
0
 
LVL 1

Accepted Solution

by:
snifong earned 50 total points
ID: 2328208
#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
 

Author Comment

by:begin
ID: 2331502
snifog, thanks for solving the core error, but i could not proceed further, i get an output just "error".
--begin
0
 
LVL 1

Expert Comment

by:snifong
ID: 2334052
Let me see the *.lst file that you are using.
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

590 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question