Reputation: 1
#include iostream
using namespace std;
int main (){
int x = {5};
int width {};
cout<<x;
cout<<"Hello World";
return 0;
}
this is my error
Helloworld.cpp:8:10: error: expected ';' at end of declaration
int width {};
^
;
1 error generated.
I copied this same code on my windows laptop and it compiles perfect but not on Mac m1 I noticed x, width, and the word cost are blue on Mac but white on windows yes the iostream is
Upvotes: 0
Views: 141
Reputation:
I'm not 100% sure what this program is meant to do, but I am assuming you are trying to declare another variable (width). I rewrote the code for you below.
#include <iostream> // You need to put the header in <>
using namespace std;
int main(){
int x = 5; // You don't need the {}
int width; // I'm assuming you want this variable to be without a value or you want it to be changed by the user
cout << x << endl; // Add endl; if you want to say something on mac and that the end of the program or you'll end up with a % at the end. I use mac so...
cin >> width; // cin means user input so you can change the value of width
cout << width << endl; // Just shows width variable
cout << "Hello World" << endl; // You can remove this if you don't want it to say hello world.
return 0; // You don't need this in recent version, you can include it though
}
Upvotes: 1