Jupyter notebook error for C++ Kernel[cling]

1.6k Views Asked by At

I have installed cling kernel for using C++ in Jupiter notebook but after implementing the code

#include <iostream>
using namespace std;

int main() {

  int a;
  a=9;
  cout<<a;
  return 0;
 }

I am getting an error as ---> error: function definition is not allowed here int main() {

1

There are 1 best solutions below

4
Thomas Sablik On BEST ANSWER

In cling you don't write the whole program code. It's like a script language. You just write the lines that should be evaluated. Don't write the main function:

#include <iostream>
using namespace std;

int a;
a=9;
cout<<a;

You can also define functions in cling but then you are not allowed to write other code into the same cell.