I have a destination path and a file name as strings and I want to concatenate them with c++.
Is there a way to do this and let the program/compiler choose between / and \ for windows or unix systems?
If you wanted to do it at compile time you could certainly do something like
#ifdef WIN32
#define OS_SEP '\\'
#else
#define OS_SEP '/'
#endif
Or you could just use '/' and things will work just fine on windows (except for older programs that parse the string and only work with '\'). It only looks funny if displayed to the user that way.
As is so often the case, Boost has a library that does what you want. Here's a tutorial.
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