getline() function is not returning the expected results

Mar 5, 2010 at 10:50am
I have used this function many times but for some reason I am not getting what I expect. I am writing a parser program, everything is working well but when I tried to get the first lexeme (word or operator) the program kept returning { which was not in the input file, I then tried to use getline() and I got this as a result: {\rtf1\ansi\ansicpg1252\cocoartf949\cocoasubrtf540

Does anyone have any idea why this occurred?? I am using a mac and i was not sure if using an rtf file as my input file made a difference

Here is the main function:
[code]

main()
{
ifstream datafile ("dataFile.rtf");
string line;

if (datafile.is_open())
{
while (! datafile.eof())
{
//char temp;
//temp = datafile.get();
// cout << temp << endl;

getline (datafile, line);
cout << line << endl;

getChar();

do
{
//lex();
}
while (nextToken != EOF);

}

} else {

cout << "ERROR - cannot open data.rtf \n";

}

}
Last edited on Mar 5, 2010 at 10:51am
Mar 5, 2010 at 11:23am
That seems like part of the first line of an RTF file to me. I don't think there's anything wrong.

Please excuse me if this sounds silly, but have you looked at the file in notepad?
Mar 5, 2010 at 4:48pm
Yeah an RTF file will contain more than just the text that you would see in an RTF editor. It'll contain all of the special codes for the formatting. This should be easy to figure out simply by looking at the RTF file within a plain text editor so that you can see the special codes and this will tell you exactly what will be read by the getline call.
Mar 5, 2010 at 5:52pm
thanks so much!!! I knew that line came from somewhere but I wasn't sure where, im new to macs. Is there a way to turn the formating off?
Mar 5, 2010 at 6:08pm
An RTF file has formatting.

http://en.wikipedia.org/wiki/Rich_Text_Format
Mar 5, 2010 at 6:50pm
thanks so much!!! I knew that line came from somewhere but I wasn't sure where, im new to macs. Is there a way to turn the formating off?


Sure, open the file within an RTF editor and resave it as plain text and all of the formatting will be removed.
Topic archived. No new replies allowed.