Connecting Tech Pros Worldwide Forums | Help | Site Map

error problen 'unexpected end of file'

Newbie
 
Join Date: Apr 2007
Posts: 4
#1: Apr 21 '07
Hello..
I have a problem when I compile the .cpp file, an error is occurred 'unexpected end of file ' plz help me why does it happen .

JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#2: Apr 21 '07

re: error problen 'unexpected end of file'


Count and match your curly brackets; you missing at least one rigth curly bracket.

kind regards,

Jos
Newbie
 
Join Date: Apr 2007
Posts: 4
#3: Apr 21 '07

re: error problen 'unexpected end of file'


Quote:

Originally Posted by JosAH

Count and match your curly brackets; you missing at least one rigth curly bracket.

kind regards,

Jos

hi Jos thanks .
I have check it twice there is no such brakets missing. I am tring it again . Tell me may be the another reason of it .
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#4: Apr 21 '07

re: error problen 'unexpected end of file'


Quote:

Originally Posted by eshuv

hi Jos thanks .
I have check it twice there is no such brakets missing. I am tring it again . Tell me may be the another reason of it .

Check your literal strings too " ... "; if you forget the closing double quote the
compiler expects more text while the end of your file has been reached. Also
check your parentheses etc. Most of the time the curly brackets are the
guilty ones.

kind regards,

Jos
Moderator
 
Join Date: Mar 2007
Location: North Bend Washington USA
Posts: 5,379
#5: Apr 21 '07

re: error problen 'unexpected end of file'


If you are using Visual Studio, each file must end with a line consisting of just the enter key.

Edit each nof your files and be sure there is an empty line at the end. This will be easy to see by going to the end of the file and looking at the cursor. If it's not in col 1 of a new line, then press enter.
Banfa's Avatar
AdministratorVoR
 
Join Date: Feb 2006
Location: South West UK
Posts: 6,195
#6: Apr 22 '07

re: error problen 'unexpected end of file'


Quote:

Originally Posted by weaknessforcats

If you are using Visual Studio, each file must end with a line consisting of just the enter key.

I have to say that I have never noticed that with visual studio. However it is part of the C and C++ standards that every line containing code must end with a newline, and I have come across a few compilers that check for this (Visual Studio not being one of them up to now), this causes a problem if for instance you don't put a newline after the closing brace of the last function in the file (something that is not visually obvious in most editors).


Another cause of you problem could be poorly positioned /closed comments. Although less likely in these days of chroma coded editors where commented out code is normally obvious if you accidentally managed to comment out a closing brace this would have the same effect as leaving it out.

It is of course possible to achieve the same effect with preprocessor directives (#if etc) instead of comments.
Reply