There are a few ways to do it.
1: Be very careful and don't use any operating system specific calls. In other words, it becomes a command line program and text interface. You still have to compile it for each operating system and there still may be some operating system specific calls that must be included for each. That is what make files are for. This solution is totally free. It also has the advantage of not needing to distribute executables for all operating systems. You can just distribute one set of source code.
2: Use an emulator on 2 of the 3 operating systems. One program compiled for one operating system. This has it's own problem of requiring an emulator that is capable of running your program. If you get to deep into Windows, it might not work completely on other operating systems. Free emulators are generally available for Linux and MacOS.
3: Use a universal library. There are some libraries available that streamline writing universal code for more than one operating system. Several are Linux and Windows compatible, but it might be difficult to find something that will work with all three. Using such a library will bring with it another set of difficulties mostly associated with the limits of the library. This solution is the most likely to have some sort of cost associated with it.
4: You could write operating system specific code which would require access to the operating systems to test them. This is probably the worst choice because you'd have to make changes to 3 different source code sets and it would be easy to get things jumbled.
C and C++ are supposed to be "portable" between operating systems. A major problem is they have severe limits. You have to decide which way you want to go and if it is really worth it to maintain a program compatible with more than one operating system.
Shadow Wolf