Connecting Tech Pros Worldwide Forums | Help | Site Map

Declaration Syntax Error

Newbie
 
Join Date: Sep 2008
Posts: 1
#1: Sep 2 '08
#include <iostream.h>
int main()
{
cout<<"Welcome to C++";
}

This program is not working

JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#2: Sep 2 '08

re: Declaration Syntax Error


Oh dear.

kindest regards,

Jos
Moderator
 
Join Date: Mar 2007
Location: North Bend Washington USA
Posts: 5,375
#3: Sep 2 '08

re: Declaration Syntax Error


Please explain what you mean by not working. Are you getting an error? If so, what is the error?
Ganon11's Avatar
Moderator
 
Join Date: Oct 2006
Location: New York, United States of America
Posts: 3,428
#4: Sep 2 '08

re: Declaration Syntax Error


1) You are using iostream.h, which is now deprecated. Leave off the .h

2) You don't output either a '\n' character or the std::endl character. cout sometimes does not print until one of these two is printed (Stick with std::endl)

3) You refer to cout as cout, not std::cout. Either write std::cout or say using std::cout at the beginning of your program, under the #include statement.

4) You are not returning 0, but you have told the compiler that main returns an int by saying "int main()". Add "return 0;" after your cout statement.

These 4 problems are very basic issues. If you copied and pasted this code from a website, don't go there again. If you copied it from a textbook, get a new textbook. If you wrote it yourself from what you learned in class, go over your notes and fix these mistakes.
Reply