Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Why Am I Getting an Inverted Question Mark?

Reply
Thread Tools

Why Am I Getting an Inverted Question Mark?

 
 
Phil Staite
Guest
Posts: n/a
 
      03-14-2005
Seems odd. Maybe, just maybe there is an empty or blank line at the
beginning of your source file? In that case during the first iteration
of the while loop line would be empty. Now, it *should* be ok to call
write with a char count of 0 and have it do nothing... But maybe there
is a problem with your stream code? Try adding a simple test:

while (getline(in,line)) {
if( ! line.empty() )
{
out.write(line.c_str(),line.size());
out.put('\n');
}
}
 
Reply With Quote
 
 
 
 
mary
Guest
Posts: n/a
 
      03-14-2005
When I read an HTML file starting with

<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">

and then I write it into another file, say OUTPUT.txt, I get an
inverted question mark, "",
at the beginning of the OUTPUT.txt file. Why is that?
Thanks!

mary

PS. I use:

string line;
while (getline(in,line)) {
out.write(line.c_str(),line.size());
out.put('\n');
}
 
Reply With Quote
 
 
 
 
mary
Guest
Posts: n/a
 
      03-14-2005
Phil,

Here is the code. It still does it with any file starting with
anything!
Thanks!

Mary

@@@@@@@@@@@@@@@@@@@@@@@

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

string line;
int main()
{
ifstream in("INPUT.txt",ios::in);
if (!in) {
cout << "Cannot Open the INPUT file.\n";
return 1;
}
ofstream out("OUTPUT.txt",ios:ut);
if (!out) {
cout << "Cannot Open the OUTPUT file.\n";
in.close();
return 1;
}
while (getline(in,line)) {
if( ! line.empty() ) {
out.write(line.c_str(),line.size());
out.put('\n');
}
}
in.close();
out.close();
return 0;
}

@@@@@@@@@@@@@@@@@@@@@@@@
On Sun, 13 Mar 2005 21:26:05 -0700, Phil Staite <(E-Mail Removed)>
wrote:

>Seems odd. Maybe, just maybe there is an empty or blank line at the
>beginning of your source file? In that case during the first iteration
>of the while loop line would be empty. Now, it *should* be ok to call
>write with a char count of 0 and have it do nothing... But maybe there
>is a problem with your stream code? Try adding a simple test:
>
>while (getline(in,line)) {
> if( ! line.empty() )
> {
> out.write(line.c_str(),line.size());
> out.put('\n');
> }
>}


 
Reply With Quote
 
Phlip
Guest
Posts: n/a
 
      03-14-2005
mary wrote:

> When I read an HTML file starting with
>
> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
>
> and then I write it into another file, say OUTPUT.txt, I get an
> inverted question mark, "",
> at the beginning of the OUTPUT.txt file. Why is that?


Are you saving the file with Notepad.exe?

That program prefixes files that it perceives as Unicode (even UTF- with a
Byte Order Mark. If you use an editor to open your file in hex (or "binary")
mode, you might see the BOM, FEFF or FFEF, at the beginning.

Your output system does not interpret the codes as UTF-8, so it probably
uses ISO Latin-1. That has no glyph for FF or EF, so you get a "missing
glyph" symbol as .

This could all be wrong, but the details are off-topic, so nobody is allowed
to contradict me.

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces


 
Reply With Quote
 
Kurt Stutsman
Guest
Posts: n/a
 
      03-14-2005
mary wrote:
> out.write(line.c_str(),line.size());
> out.put('\n');


I don't see anything wrong with your code, but the above lines could be
simplified to:
out << line << '\n';
 
Reply With Quote
 
Sven Axelsson
Guest
Posts: n/a
 
      03-14-2005
On Mon, 14 Mar 2005 06:16:12 GMT, Phlip wrote:

> mary wrote:
>
>> When I read an HTML file starting with
>>
>> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
>>
>> and then I write it into another file, say OUTPUT.txt, I get an
>> inverted question mark, "",
>> at the beginning of the OUTPUT.txt file. Why is that?

>
> Are you saving the file with Notepad.exe?
>
> That program prefixes files that it perceives as Unicode (even UTF- with a
> Byte Order Mark. If you use an editor to open your file in hex (or "binary")
> mode, you might see the BOM, FEFF or FFEF, at the beginning.
>
> Your output system does not interpret the codes as UTF-8, so it probably
> uses ISO Latin-1. That has no glyph for FF or EF, so you get a "missing
> glyph" symbol as .
>
> This could all be wrong, but the details are off-topic, so nobody is allowed
> to contradict me.


Well, your reasoning is correct, but not your facts. A Unicode file may
start with FEFF or FFFE (not FFEF) to indicate endianness. A UTF-8 file,
however, starts with EFBBBF if it has a BOM mark at all. But, no doubt, the
BOM mark is what the OP is seeing.

--
Sven Axelsson, Sweden
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why is video inverted for transmission? Green Xenon [Radium] Digital Photography 266 10-13-2007 06:11 PM
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
replace double inverted commas into slash double inverted commas in string AviraM Java 2 09-28-2006 06:19 PM
Getting rid of inverted commas around a string. Fearban@gmail.com Perl Misc 8 05-25-2006 06:10 PM



Advertisments