Fixing Segmentation Fault

Fixing Segmentation Fault

I have to run this code for my class, most of what we use is java, I don't really know c++, but the code I have to run is c++, so I'm finding it difficult to debug or know what's going wrong. To compile it, I'm using a unix virtual machine. I've compiled it and have the a.out file in my directory. When I run the a.out file it says "segmentation fault". I've read that means it's trying to access something it can't, but I don't know what that would be. Is it a problem with the code they gave us, or could it be something like a setting on my machine?

I have to run this code for my class, most of what we use is java, I don't really know c++, but the code I have to run is c++, so I'm finding it difficult to debug or know what's going wrong. To compile it, I'm using a unix virtual machine. I've compiled it and have the a.out file in my directory. When I run the a.out file it says "segmentation fault". I've read that means it's trying to access something it can't, but I don't know what that would be. Is it a problem with the code they gave us, or could it be something like a setting on my machine?

#include <iostream>
#include <fstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <iostream>
#include <stdio.h>

using namespace std;

int main(int argc, char *argv[]) { int N; sscanf(argv[1], "%d", &N); vector<double> data(N); for(unsigned int i=0; i<N; i++) { data[i] = rand()/(RAND_MAX+1.0); } sort(data.begin(), data.end()); copy(data.begin(), data.end(), ostream_iterator<double>(cout,"\n")); }


Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

C/C++ vs. Rust: A developer’s perspective

In this post, you'll see the difference between Rust and C/C++ in a developer’s perspective

Variable Introduction in C#[Bangla]

LIKE | COMMENT | SHARE | SUBSCRIBE A variable is nothing but a name given to a storage area that our programs can manipulate. Each variable in C# has a speci...