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; } 22 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:
1Try 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.