#include<iostream>
using namespace std;
int main()
{
cout << "Welcome to this video"<<"\n";
int a;
a = 10;
switch (a) {
default:
cout << "default is executed whatever happens";
case 10:
cout << "a is 10" << "\n";
case 5:
cout << "a is now 5" << "\n";
}
return 0;
}
This is my code. When I am trying to comment line:
default:
cout << "default is executed whatever happens";
and then when I am saving and running the code I am getting the error
C:/Program Files/mingw-w64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o):crt0_c.c:(.text.startup+0x2e): undefined reference to `WinMain'
collect2.exe: error: ld returned 1 exit status
But when I am closing and opening my terminal 2-3 times and then running the code, my code is working fine after 2-3 attempts. Similarly when I am uncommenting the commented code and when I am trying to run it I am getting error:
tempCodeRunnerFile.cpp:1:7: error: expected unqualified-id before 'default'
default:
Can anyone please tell me why C++ is working like this. I am using VS code as my code editor and my GCC version is 8.1.0.