Trying to run a cpp program that gives back the union of two arrays. Computer is a M1 Pro Macbook Pro 14.2 inch with Mac OS Monterey 12.6. Using VSCode with the C/C++ extensions, and Coderunner. I was having problems with running cpp programs on Vscode before as well, so I followed a bunch of different guides trying to figure it out. Some were installing mingw-w64 with homebrew, some gcc, most used coderunner, which is why I stuck with it.
#include<iostream>
#include <vector>
using namespace std;
//this code works only for sorted arrays, notice the
void Find_Union(int arr1[],int arr2[], int n, int m)
{
vector <int> Union;
int i = 0, j = 0;
while(i<n && j<m)
{
if(arr1[i]<=arr2[j])
{
if (Union.size() == 0 || Union.back() != arr1[i])
{
Union.push_back(arr1[i]);
i++;
}
}
else
{
if (Union.size() == 0 || Union.back() != arr2[j])
{
Union.push_back(arr2[j]);
j++;
}
}
}
while (i < n) // IF any element left in arr1
{
if (Union.back() != arr1[i])
Union.push_back(arr1[i]);
i++;
}
while (j < m) // If any elements left in arr2
{
if (Union.back() != arr2[j])
Union.push_back(arr2[j]);
j++;
}
for(auto &it: Union)
{
cout<<it<< " ";
}
}
int main()
{
int arr1[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int arr2[] = {2, 3, 4, 4, 5, 11, 12};
int n = sizeof(arr1)/sizeof(arr1[0]);
int m = sizeof(arr2)/sizeof(arr2[0]);
Find_Union(arr1,arr2,n,m);
return 0;
}
For some reason, when trying to run this code, I get the following error:
UnionOfTwoSortedArrays-Pointers.cpp:44:9: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
for(auto &it: Union)
^
UnionOfTwoSortedArrays-Pointers.cpp:44:17: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
for(auto &it: Union)
The error is for when I'm trying to use auto iterator to print out the elements of the Union vector using cout.
I've tried to mess around with the DefaultL: Cpp Standard extension settings for the C/C++ extensions, and have also tried to edit the executor map setting for Cpp language in Code Runner's extension settings.
As a side note, using #include<bits/stdc++.h> is also gonna need some finangling I haven't gotten around to yet. Does anyone have some clear tutorial I could follow for running cpp code on VSCode on M1 Macs or some kind of fix?