Hi,
I'm just trying to print the contents of a notepad file I saved with
unicode encoding on my win xp machine. I keep getting strange
characters printed out though. Why doesn't this work?
std::wifstream wifile("C:\\uni code.txt");
if (wifile.is_open ()) {
wchar_t wszBuffer[MAX_PATH];
while (wifile.getline (wszBuffer, MAX_PATH)) {
AfxMessageBox(w szBuffer);
}
}
My unicode saved file just has the contents "hello" in it, but my
message box prints some crazy stuff.
Thanks 1 4066
markww wrote:
Hi,
I'm just trying to print the contents of a notepad file I saved with
unicode encoding on my win xp machine.
There are at least three ways to do that, and that's just counting
Notepad.
There are more ways to serialize Unicode.
I keep getting strange
characters printed out though. Why doesn't this work?
std::wifstream wifile("C:\\uni code.txt");
if (wifile.is_open ()) {
wchar_t wszBuffer[MAX_PATH];
while (wifile.getline (wszBuffer, MAX_PATH)) {
AfxMessageBox(w szBuffer);
}
}
Basically, because wifstream doesn't understand Unicode. What you need
is "a" unicode codecvt. Since there are multiple ways to serialize
Unicode,
which codecvt you need depends the encoding. And unfortunately, the
standard doesn't require one Unicode codecvt. You might need to buy
one.
The easier solution, in many cases: Restrict yourself to UTF-8; read
entire
lines at a time, and convert them yourself.
HTH,
Michiel Salters This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Achim Domma |
last post by:
Hi,
I read some text from a utf-8 encoded text file like this:
text = codecs.open('example.txt','r','utf8').read()
If I pass this text to a COM object, I can see that there is still the BOM
in the file, which marks the file as utf-8. Simply removing the first
character in the string is not ok, because the BOM is optional. So I tried
something like this:
|
by: Guyon Morée |
last post by:
what is the difference?
if I open a text file in binary (rb) mode, it doesn't matter... the read()
output is the same.
|
by: hunterb |
last post by:
I have a file which has no BOM and contains mostly single byte chars. There
are numerous double byte chars (Japanese) which appear throughout. I need to
take the resulting Unicode and store it in a DB and display it onscreen. No
matter which way I open the file, convert it to Unicode/leave it as is or
what ever, I see all single bytes ok, but double bytes become 2 seperate
single bytes. Surely there is an easy way to convert these mixed...
|
by: hezhenjie |
last post by:
Hi, all:
I just need to parse a unicode file, and assume to get data one line
by one line.
I use _wfopen(), fgetws(), wcslen(), wcsstr(), making it work
normally on Windows platform.
However, when migrate it to Linux platform, issue occurs.
Linux only has fopen() function, and fgetws() could not correctly get
lines, in fact, it gets nothing.
|
by: Kueishiong Tu |
last post by:
I have a text file with wide characters. I use the following C++ code to read
them in. However the wide characters are not read in properly. What is wrong?
String* path = "C:\\Documents and Settings\\kst\\BE.dat";
try
{
FileStream* fs = new FileStream(path, FileMode::Open);
StreamReader* sr = new StreamReader(fs);
| |
by: Tibby |
last post by:
I need to read/write not only text files, but binary as well. It seems like on binary files, it doesn't right the last 10% of the file.
--
Thanks
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.538 / Virus Database: 333 - Release Date: 11/10/2003
|
by: Ahmed A. |
last post by:
This will be very helpfull for many!
Using RichTextBox Read/Write Unicode File
http://www.microsoft.com/indonesia/msdn/wnf_RichTextBox.as
p
Private Function ReadFile(ByVal myfile As String) As
String
Dim myFileStream As Stream = File.Open(myfile,
FileMode.Open)
|
by: starffly |
last post by:
I want to read a xml file in Unicode, UTF-8 or a native encoding
into a wchar_t type string, so i write a routine as follows, however,
sometimes a Unicode file including Chinese character cannot be read
completely. and I cannot tell where its root located, so NEED your
help, GIVE me a hand please.
THX.
static Status LoadXMLFile2String(const char *filename, wchar_t *text){
FILE *f;
if(!(f = fopen(filename, "r"))){
__printDebugA("Input...
|
by: Zoro |
last post by:
My task is to read html files from disk and save them onto SQL Server
database field. I have created an nvarchar(max) field to hold them.
The problem is that some characters, particularly html entities, and
French/German special characters are lost and/or replaced by a
question mark.
This is really frustrating. I have tried using StreamReader with ALL
the encodings available and none work correctly. Each encoding handles
some characters...
|
by: Steve Holden |
last post by:
ganesh gajre wrote:
You are getting too ambitious. Text files don't have any font
information associated with them. Not only that, but the encoding of
Unicode character data is independent of the font used to render the
readable glyphs as text.
This makes it look as though you don't really know what you are doing.
Perhaps you should start more slowly, and try explaining the real problem.
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |