|
From: Ioannis V. <iv...@em...> - 2003-06-30 00:12:35
|
> -----Original Message-----
> From: dev...@li...=20
> [mailto:dev...@li...] On Behalf=20
> Of David McKen
> Sent: Monday, June 30, 2003 2:31 AM
> To: Dev-Cpp Mailing List
> Subject: [Dev-C++] Portable End-of-Line
>=20
>=20
> Is there a portable way of finding out the end-of line
> sequence for the
> current operating system? I hope to make my program
> portable to both Win +
> *NIX and would like something more (what word could go
> here?) than:
>=20
> #ifdef WIN32
> const char DIR_SEP =3D '\\';
> const char eoln[] =3D "\n";
> #else
> const char DIR_SEP =3D '/';
> const char eoln[] =3D "\n\r";
"\n\r" also applies at least to .NET text boxes.
In any case only '\n' is portable.
> #endif
>=20
> Same applies to the directory separator. Is there a way I
> can detect which
> one is used? As I said portability is of utmost importance
> so it must be C++
> ANSI compliant (my program uses classes so it cant be a C
> compliant program.
From my limited experience those "\n\r" etc sequences apply only to GUI
programs.
Any way, about line change since '\n' exists in all cases you can detect =
it
by reading character by character. If you want to display it consider it =
as
a system extension and you can handle it as all system extensions by
encapsulating it to a small portion of your program:
Example:
// Unportable encapsulations
namespace uenc
{
const string eol=3D"\n";
inline void clearscr()
{
system("cls");
}
// ...
}
So when you want to compile the program in another platform you have =
only to
change those encapsulations.
And try to forget the ancient C style stuff where C++ provides superior
alternatives.
Ioannis Vranos
=20
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL 1: http://run.to/noicys
* Alternative URL 2: http://www.noicys.cjb.net
|