0

One of the cpp file I tried to compile gave me that error. The cpp file I am working on is literally a copy of 2 other .cpp files, except this handles different values and have different calculation. I don't understand why the other files can compile, but not this one.

Assuming that "" is actually a cryllic letter ï, but I do not have such character in my code.

The exact error message is:

"TelephoneBill.cpp", line 1: Error: A declaration was expected instead of "". "TelephoneBill.cpp"."TelephoneBill.cpp", line 1: Error: "," expected instead of ""TelephoneBill.h"".

I have cut out the unnecessary parts, but the code is:

#include "TelephoneBill.h"                           //line 1

istream& operator>>(istream& in, TelephoneBill* b)
{
   //...
}

//...

Anyone has an idea about what is going on here?

Thanks in advance!

Vince
  • 121
  • 1
  • 9
  • 7
    Looks like BOM (Byte Order Mark). It is BOM for UTF-8: http://en.wikipedia.org/wiki/Byte_order_mark#UTF-8 – nhahtdh May 10 '13 at 07:29
  • @nhahtdh Is there a way to get around this problem? – Vince May 10 '13 at 07:44
  • Can you do some search on SO/Google with the possible cause that I have pointed out? I actually don't know the answer myself. – nhahtdh May 10 '13 at 07:50
  • I have read http://stackoverflow.com/questions/3255993/how-do-i-remove-i-from-the-beginning-of-a-file but I cannot do anything with the way things are read on the school's computer. Plus I have to make sure the program can compile in my lecturer's machine as well. – Vince May 10 '13 at 07:50
  • 1
    Trust me, I am not just here expecting to be spoonfed the answer, I am looking for solution myself : ) – Vince May 10 '13 at 07:51
  • How do you compile your program? What is the version of the compiler? – nhahtdh May 10 '13 at 08:05
  • 2
    @Vince - what editor are you using? If it knows enough about a BOM to create a file with one (or not get confused by opening a file with one), it will usually have some option somewhere to save the file without a BOM. If push comes to shove, you can probably get rid of the BOM using a hex editor or a script such as the one here: http://thegreyblog.blogspot.com/2010/09/shell-script-to-find-and-remove-bom.html – Michael Burr May 10 '13 at 08:07
  • i connect to the university's server using SSH and compile my program there. CC task2Main.cpp ElectricityBill.cpp GasBill.cpp TelephoneBill.cpp. I create/edit my files using notepad. – Vince May 10 '13 at 08:11
  • i am just guessing when i type "version" and the result I get is: Machine hardware: sun4v, OS version: 5.10, Processor type: sparc. Hardware: sun4v. Sun Studio 12 is installed. – Vince May 10 '13 at 08:13
  • Actually, I was retyping the whole program once again (while looking for solution and waiting for an answer) in a new notepad and that fixes the BOM problem. Theres not a single word I can use to express my hatred to that evil little thing. – Vince May 10 '13 at 08:18
  • 1
    @Vince: notepad (I assume you mean Windows notepad) is a terrible tool for writing programs. There are so many free editors out there that are miles better: notepad2, notepad++, a bazillion other ones all the way up to full IDEs (those two will have zero learning curve coming from notepad, but other ones may have better project management and code navigation features). I strongly suggest looking into getting a better editor than notepad. – Michael Burr May 10 '13 at 08:30

1 Answers1

2

Thanks for the helpful comments, especially the link provided by Michael Burr in the comment section. I learned a whole lot about .

I solved the problem by retyping my code in another notepad document and the BOM problem went away just like that.

Vince
  • 121
  • 1
  • 9
  • @nhahtdh I'll have a look at that as well. Thanks! :D – Vince May 10 '13 at 08:25
  • 1
    Notepad has an option for this in the `File->Save As...` dialog. Look for the Encoding dropdown menu left to to the Save button. Setting this to anything else but ANSI will give you a BOM. – ComicSansMS May 10 '13 at 11:07
  • @ComicSansMS I am pretty sure it is ANSI since ANSI is the default, but I honestly don't remember since it was hours back. I'll keep that in mind. Thanks! – Vince May 10 '13 at 13:00