Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error C1004: unexpected end-of-file found in Visual Studio 2012

I want to write a simple C++ code in visual studio 2012 but always getting a error C1004 in the header file. Could anyone please help me?

My code is given below. I am new in visual studio C++, so this may be very silly error.

add.cpp

#include <iostream>

int add(int a, int b)
{
    return a+b;
}

add.h

#ifndef ADD_H
#define ADD_H

int add(int a, int b);

#endif

source.cpp

#include "add.h"
#include <iostream>

int main()
{
    std::cout << add(3, 4);
    return 0;
}
like image 672
Mesbahul Avatar asked Dec 08 '12 23:12

Mesbahul


2 Answers

The general code looks OK, but add.h will need a carriage return at the end of the file. Here is the Microsoft documentation for that error code:

http://msdn.microsoft.com/en-us/library/4exw7xyc%28v=vs.110%29.aspx

like image 195
PeterJ Avatar answered Nov 11 '22 19:11

PeterJ


Try copying your code to a text editor like Notepad++ and change encoding to ANSI. You may see some strange symbols, for example

int main()
{
    // ...
}п»ї

To fix the error, remove them and copy the code back.

like image 41
Pavel Avatar answered Nov 11 '22 20:11

Pavel