std::wcout << L"Numbers greater than " << num1 << L" in the 1st array are :" << std::endl;
// call the function to print the Number greater than 3
fun(arr1, num1);
// declare and initialize array
std::vector<int> arr2 = { 10, 7, 12, 17, 22 };
int num2 = 12;
std::wcout << L"Numbers greater than " << num2 << L" in the 2nd array are :" << std::endl;
// call the function to print the Number greater than 12
fun(arr2, num2);
}
catch (const std::runtime_error)
{
return;
}
}
void Main::fun(std::vector<int>& arr, int n)
{
for (int i = 0; i < arr.size(); i++)
{
// if the array element is greater than the value of n, then print it
if (arr[i] > n)
{
std::wcout << arr[i] << L" ";
}
}
std::wcout << std::endl;
}
Severity Code Description Project File Line Suppression State
Error C2664 'std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>>::basic_string(std::initializer_list<_Elem>,const _Alloc &)': cannot convert argument 1 from 'char *' to 'std::initializer_list<_Elem>' Programming Project2 C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\xmemory 714
I am unsure exaclty where the error is or how to fix it has its in the xmemory. Not sure how to adjust argument 1 to get the code to run. Any help is appreciated.
I don't see it, but its telling you that you have bad arguments to a constructor; I think its
std::vector<std::wstring> args(argv + 1, argv + argc);
if you look at your error, it will have the line number (and column) where it choked.
Its not in xmemory, that is a symptom, but one of your error messages will point to your file and a line number.
it is unusual to wrap main in an object without reason. If you have a reason, its fine. If not, its 'java like' and 'weird' in c++.
It's telling me it's in line 714 which doesn't exist for me to view.
This is an artifact of how the C++ standard library operates. Symptoms of the error appear in the implementation of the standard library rather than your code. Line 714, of a different file.
Every mainstream compiler follows the source of the error back to your code. Keep reading the error message, always top-down, until the first time it refers to a file and line number in your code. Start there.
Generally, there is no point in trying to diagnose an error by looking at the implementation of the standard library (e.g. in xmemory).
are you asking me? Most code looks like Mbozzi's above, a main function that creates some variables and kicks off another method (whether belonging to an object or not).
the extra object for "Main" was just visual clutter -- its not "wrong" but served no purpose in c++.