Is there a wxFile end of line method?

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
tbreina
Moderator
Moderator
Posts: 1289
Joined: Thu Nov 25, 2004 7:38 pm
Location: Coronado, CA

Is there a wxFile end of line method?

Post by tbreina » Sat Jan 08, 2005 12:15 pm

I'm saving a simple text file using wxTempFile.

Currently, I'm just adding the "\r\n" to the end of strings written to the file to declare a newline. However, for portability between Windows and Unix is there a generic EOL method? Something like cout << endl in the standard namespace?

Thanks.
-Tony

prophet
Knows some wx things
Knows some wx things
Posts: 32
Joined: Wed Sep 01, 2004 6:19 am

Post by prophet » Sat Jan 08, 2005 8:51 pm

Yes, there is.

Maybe you should read the documentation first

eco
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 203
Joined: Tue Aug 31, 2004 7:06 pm
Location: Behind a can of Mountain Dew
Contact:

Post by eco » Sun Jan 09, 2005 8:17 am

There is no reason to be short with people, especially when you are wrong. Nowhere in the documentation of wxTempFile or the base class of wxFile does it mention end of lines (let alone, crossplatform issues of them). In fact, I searched the entire wxWidgets website and the mailing list and could see no immediate answer to this question.

The wxStream based classes should use endl just fine on the other hand. Anyone know the answer to this? I'm curious myself.

tbreina
Moderator
Moderator
Posts: 1289
Joined: Thu Nov 25, 2004 7:38 pm
Location: Coronado, CA

Re: Is there a wxFile end of line method?

Post by tbreina » Sun Jan 09, 2005 5:59 pm

Thanks for watching my back Eco.

Prophet: Perhaps YOU'RE the one who needs to read the documentation first. I've searched both the documentation and forum and can't find anything useful for wxTempFile. There are some references to determining the end of line character when READING a file that already exists, but I can't find how to specify it when WRITING the text file line by line.

As Eco suggested, I had thought of using std::endl. Something like:

wxTempFile file;

file.Write("Line 1" << endl);

However, I can't seem to get this one to work.

For now, file.Write("Line 1/n/r") works, but wouldn't be useful on Unix.

Do any other platforms use different line terminations other than the Windows or Unix/Linux ways? Perhaps I'm just trying to make it too complicated.

-Tony

eco
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 203
Joined: Tue Aug 31, 2004 7:06 pm
Location: Behind a can of Mountain Dew
Contact:

Post by eco » Sun Jan 09, 2005 9:42 pm

Doing a wxString(_T("Line 1") << endl) would probably work fine actually.

Avi
Super wx Problem Solver
Super wx Problem Solver
Posts: 398
Joined: Mon Aug 30, 2004 9:27 pm
Location: Tel-Aviv, Israel

Post by Avi » Sun Jan 09, 2005 9:49 pm


tbreina
Moderator
Moderator
Posts: 1289
Joined: Thu Nov 25, 2004 7:38 pm
Location: Coronado, CA

wxTextFile::GetEOL

Post by tbreina » Mon Jan 10, 2005 8:13 am

Awesome. Thanks Avi. wxTextFile::GetEOL() did the trick.

-Tony

User avatar
Ryan Norton
Moderator
Moderator
Posts: 1319
Joined: Mon Aug 30, 2004 6:01 pm

Post by Ryan Norton » Fri Jan 14, 2005 12:34 pm

Neat! I didn't know that :).
[Mostly retired moderator, still check in to clean up some stuff]

Avi
Super wx Problem Solver
Super wx Problem Solver
Posts: 398
Joined: Mon Aug 30, 2004 9:27 pm
Location: Tel-Aviv, Israel

Post by Avi » Sat Jan 15, 2005 8:36 pm

Ya, I've used it once writing some basic INI writing/parsing class: IniBuffer.h, IniBuffer.cpp
:)

mjs
Experienced Solver
Experienced Solver
Posts: 93
Joined: Wed Feb 09, 2005 3:53 am
Contact:

Post by mjs » Wed Feb 09, 2005 6:20 am

What about wxFileName::GetPathSeparators()?

Regards,
Mark

Post Reply