//test.h
#ifndef TEST_H //header guard
#define TEST_H
#pragma once //alternative
#include <iostream> //to use cout
#include <string> //to use string
//you cannot have function definition in headers (except if they are inline or template)
inline display(std::string s){
std::cout << s << std::endl;
}
#endif
1 2 3 4 5 6 7 8 9
//main.cpp
#include "test.h" //to use display()
#include <string> //to use string
int main(){
std::string foo = "bar";
display( "Test123" );
display( foo );
}
This is non-standard by widely supported extension which works like header guards, but often has added bonuses (like not even opening that file second time). However many compilers can recognise header guards and add tose bonuses to them as well.
What if you decide to compile your program on compiler which does not support #pragma once ? It is better to have it in addition to standard way of doing this. I usually do not even care, as many compilers extend it advantages to header guards too and for historical reasons (pragma once did not work on two different files with same content)