2 Replies - 3050 Views - Last Post: 12 February 2010 - 02:49 PM Rate Topic: -----

#1 Magmatwister  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 50
  • Joined: 24-November 09

Multiple Delimiters In Text Files

Posted 12 February 2010 - 02:38 PM

I'm trying to write a program, and I need to be able to use new line, AND ">" as delimmiters. Can anyone help me? My code isn't really relevant, but here is a sample:
while(!RecordFile.eof() ) 
{
   getline(RecordFile, Content, '>');

   if (Content == "<MouseCORDS")
   { 
//Whatever I'm going to do...






Text file:


<MouseCORDS> 65> 94>
<KeyboardCommand>  43>




I can get the first line completely fine. However, after 94 has been read (It stops at ">"), it will read WHITESPACE, and then <keyboardcommand, so the following:

if(Content == "<KeyboardCommand")
{
}

will not work, because what's really in content is:
".........................................<KeyboardCommand"
Or something to the like. I can't specify multiple delimmiters in a single getline statement, so some help would be appreciated as to how I would go about doing this.

This post has been edited by Magmatwister: 12 February 2010 - 02:39 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Multiple Delimiters In Text Files

#2 Anarion  Icon User is offline

  • The Persian Coder
  • member icon

Reputation: 282
  • View blog
  • Posts: 1,456
  • Joined: 16-May 09

Re: Multiple Delimiters In Text Files

Posted 12 February 2010 - 02:45 PM

Mentioned [ Here ]

Note that, for reading files, don't use eof. Because it only stops when trying to read past the end of file which is not suitable.

You may want to have a look at [ This Tutorial ] which explains this approach.
Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5960
  • View blog
  • Posts: 23,238
  • Joined: 23-August 08

Re: Multiple Delimiters In Text Files

Posted 12 February 2010 - 02:49 PM

You could also use Boost's tokenizer.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1