473,396 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Why Am I Getting an Inverted Question Mark?

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');
}
Jul 23 '05 #1
5 6339
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');
}
}
Jul 23 '05 #2
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::out);
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 <ph**@nospam.com>
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');
}
}


Jul 23 '05 #3
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-8) 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
Jul 23 '05 #4
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';
Jul 23 '05 #5
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-8) 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
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Kiki Novak | last post by:
Hi, I'm an Austrian writer living in Montpezat (South France), and I'm currently busy converting some of my writings from LaTeX to HTML to publish them on the Internet. The novel I'm working...
16
by: rorley | last post by:
I'm new to Python and I'm struggling. I have a text file (*.txt) with a couple thousand entries, each on their own line (similar to a phone book). How do I make a script to create something like...
0
by: Logan | last post by:
I am drawing the current cursor on a zoomed in view of the desktop which seems to be work for all of the cursor types, except that the IBeam is always being drawn inverted (white) even when it...
7
by: Mark Hobley | last post by:
I have some information that states that the if conditional can be be inverted from the traditional syntax if (EXPRESSION) BLOCK to an alternative syntax: if BLOCK (EXPRESSION); I have a...
5
by: vd12005 | last post by:
Hello, While playing to write an inverted index (see: http://en.wikipedia.org/wiki/Inverted_index), i run out of memory with a classic dict, (i have thousand of documents and millions of terms,...
2
by: weird0 | last post by:
I have to create a string that contains inverted commas inside it. How can i do that in c#? As follows:- "AT+CMGF=1" string temp=""AT+CMGF=1""; // not valid
1
by: Geosondaman | last post by:
#include <stdio.h> #include <stdlib.h> int main(int argc, char *argv) { int i=0, j; while (++i<10) { j=9; while (++j<=i) { printf("*");
1
by: Shashank tiwari | last post by:
Hi I am trying Putting single inverted comma before a digit in Excel and a single inverted comma after the number and a comma to follow. Eg. '234567', Can anybody tell us how to do it for 7000...
1
by: vbiswsu | last post by:
Hi , I am facing a strange problem.I am supporting a application which is in VB and database is Oracle 9i.Now the problem is one of the production user(Say USER 1) is getting an inverted question...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.