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;
}
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With