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; } 
2

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:

1

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.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like