-9
#include <iostream>
using namespace std;

int main ()
{

int Age =25;
string name = "John";

 cout << Age name ;

  return 0;

}

compilation

In function 'int main()':

10:13: error: expected ';' before 'name'

ayman2011a
  • 13
  • 1
  • 4
  • It is unclear what you are asking. Please [clarify](https://stackoverflow.com/posts/49464406/edit) and format your code properly. – Ron Mar 24 '18 at 11:58
  • 2
  • 1
    [Any good beginners book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list/388282#388282), or heck just about *any* book, good or bad, would have thought you what you need. As will most if not all online tutorials. – Some programmer dude Mar 24 '18 at 12:01
  • I'm not asking for flawless grammar, but at the very least you should make your sentences readable. –  Mar 24 '18 at 12:01
  • I am curious as to what exactly you did to cause this error. I only get that if I write things like `cout 25;`, which you don't have in your program. – Mr Lister Mar 24 '18 at 12:22

4 Answers4

1

For C++, you need all the other important parts, such as the include files, and the namespace qualifiers.

Unlike most scripting languages, the programming statements and expressions have to be in the context of a function.

For example:

#include <iostream>
#include <string>

using std::cout;
using std::endl;
using std::string;

int main()
{
  int Age = 25;
  string name = "John";
  cout << Age << " " << name << endl;
  return 0;
}
Eljay
  • 4,648
  • 3
  • 16
  • 27
  • It isn't necessary to use `std::endl`. Better to use `\n` and in that way you avoid the second `using`. – Xam Mar 24 '18 at 14:26
  • @Xam • I'm not sure what version of C++ the OP is using. The OP had not used `\n` nor `endl` nor `flush`. The `endl` will do the newline and flush. Older C++ compilers may not necessarily flush the `cout` on termination, which could be a reason for not seeing the output. – Eljay Mar 24 '18 at 15:26
0

The error says that there's a missing semicolon somewhere, your compiler should tell you in which line is the error and you might find it. Also you should do all the previous steps in the c++ code as following :

#include <iostream>

using namespace std;

int main()
{

  int age = 25;
  string name= "john";

  cout<<"The age is: "<<age<<endl;
  cout<<"The name is: "<<name<<endl;

  return 0;
}

if there's still a problem please clarify it.

0
#include <iostream>
#include <string>
using namespace std;

int main()
{
int Age ;
Age = 32;
string name ;
name =  "ahmed";
cout << "age is"<< Age << "  " <<endl;
cout<< "name is " << name << endl;
return 0;

try this

jamie's
  • 9
  • 2
-3
#include <iostream> 
using namespace std;
 int main(){

int Age =25; string name = "John";

 cout<< name << "  age ="<<Age;}

you mean that