Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8916807

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:20:15+00:00 2026-06-15T05:20:15+00:00

I have a problem with the segmentation fault. Look: #include<fstream> using namespace std; int

  • 0

I have a problem with the segmentation fault.
Look:

#include<fstream>
using namespace std;
int main(){
    int n,i,vector[10001],vectorcopy[10001];
    ifstream in("program.in");
    ofstream out("program.out");
    in>>n;
    for(i=1;i<=n;i++){
        in>>vector[i];
        vectorcopy[i]=vector[i];
    }
    return 0;}

And the debugger says:
Program recived signal SIGSEGV, Segmentation fault

Please, tell me what to do!

  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:20:17+00:00Added an answer on June 15, 2026 at 5:20 am

    Your program is (mostly) working correctly, if the input file program.in is correct. I suppose your segmentation fault error is caused by:

    • bad input
    • the lack of input checking in your program

    I got no errors with this program.in input file:

    10
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    

    Other errors

    I said “mostly” because there are a few other errors in your program. They are not causing trouble (C++ calls this “undefined behaviour”) right now, but sooner or later they will:

    • for an array of size n, indexes start at 0 and end at n - 1; when using arrays, do not write your for statement like this:

      for (i = 1; i <= n; i++)
      

    just rewrite it as:

        for (i = 0; i < n; i++)
    
    • you are not using the vectorcopy array
    • you are not writing anything to the program.out output file
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I faced a problem using a Boost variant. I have a segmentation fault when
Possible Duplicate: Segmentation Fault - C #include<stdio.h> #include<string.h> int main() { char *p; printf(enter
I have segmentation fault problem with my multiple class files project. Without making empty
I have a segmentation fault problem occurring at the very end of my program.
I have written a segmentation fault handler, using sigsetjmp and siglongjmp. Once it goes
The segmentation fault is caused in the scanner code. The Problem: Using GDB to
I have problem with my query on C, I’m using the oci8 driver. This
I have a qApp that generates a segmentation fault only when a breakpoint is
I have a problem putting data into an unordered_map using a struct as key:
I have implemented a class string, similar to std::string one. I have a problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.