So, I'm new to C++. I need to learn this language quick for school. But I'm walking against some issues that make it difficult to work with this language. I downloaded visual studio code and followed the steps given by my school. But now I have the problem that sometimes my code just won't print.
Here is an example of a piece of code that does print (btw, I use a "makefile" to run all of this):
#include <iostream>int main(){ std::cout << "Hello world!" << std::endl; return 0;}
Ofcourse, just a simple "hello world" but still, it does print. Now I'll give an example of a piece of code that won't print:
// C++ program to sort an// array using bucket sort#include <algorithm>#include <iostream>#include <vector>using namespace std;// Function to sort arr[] of// size n using bucket sortvoid bucketSort(float arr[], int n){ cout << "hello" << endl; // 1) Create n empty buckets vector<float> b[n]; // 2) Put array elements // in different buckets for (int i = 0; i < n; i++) { int bi = n * arr[i]; // Index in bucket b[bi].push_back(arr[i]); } // 3) Sort individual buckets for (int i = 0; i < n; i++) sort(b[i].begin(), b[i].end()); // 4) Concatenate all buckets into arr[] int index = 0; for (int i = 0; i < n; i++) for (int j = 0; j < b[i].size(); j++) arr[index++] = b[i][j];}/* Driver program to test above function */int main(){ cout << "hello" << endl; float arr[] = { 0.897, 0.565, 0.656, 0.1234, 0.665, 0.3434 }; int n = sizeof(arr) / sizeof(arr[0]); bucketSort(arr, n); cout << "Sorted array is \n"; for (int i = 0; i < n; i++) cout << arr[i] << " "; return 0;}
This is an example of a bucket sort I found online. First, the "n" on the vector<float> b[n]
line, gave a red line, I chose the "ignore this error" option. Second, this code won't output anything. If I look into the "debug console" I find this error: ERROR: Unable to start debugging. Unexpected GDB output from command "-exec-run". During startup program exited with code 0xc0000139.
When I looked online I saw some people give the advice to downgrade my gdb version. I want to try that, but I can't find out how to do that haha. Can someone help me get my visual studio code working? This is the most irritating part of programming to me.