不同的文件大小C ++到C# [英] Different file sizes C++ to C#
问题描述
大家好,我刚刚被要求将一些旧的遗留C ++代码移植到C#,程序非常简单 - 它从文本文件中解析一些数据并将其写入另一个。一切正常但是 - 作为我测试的一部分,每当我做这样的事情时,我都会使用devenv.exe中的文件比较功能(以为它曾经被称为windiff)
Hi All, I've just been asked to port some old legacy C++ code to C#, the program is pretty simple - it parses some data from a text file and writes it out to another. All works ok BUT - as part of my testing whenever I do stuff like this I use the file compare function in devenv.exe ( think it used to be called windiff )
devenv /diff file1 file2
一切都很好,但是 - 如果我逐字节比较它会失败,因为文件大小不同(C#one大128个字节)
任何想法的人?它不是一个节目限制器我只是好奇。
我尝试过:
在这里搜索和发布!
and all is good, BUT - If I do a byte by byte comparison it fails as the files are different sizes ( the C# one is 128 bytes larger)
Any ideas guys ? it's not a show stopper I'm just curious.
What I have tried:
Googling and posting on here !
推荐答案
在 Notepad ++ 编辑器中打开文件,然后查看菜单选项 编码。
我认为您的C ++文件是ANSI,而您的C#文件是Unicode,每个字符最多使用2个字节。请参阅: Unicode - 维基百科 [ ^ ]和 C#深度:Unicode和.NET [ ^ ]
在C#中使用Encoding.ASCII
以ascii格式写入文件。
您还可以转换为ASCII:
Open your files in the Notepad++ editor, and look at the menu option "Encoding".
I think your C++ file is in ANSI and your C# file in Unicode which uses up to 2 bytes per char. See: Unicode - Wikipedia[^] and C# in Depth: Unicode and .NET[^]
In C# useEncoding.ASCII
to write to a file in ascii format.
You can also convert to ASCII:
Encoding ascii = Encoding.ASCII;
Encoding unicode = Encoding.Unicode;
byte[] asciiBytes = Encoding.Convert(unicode, ascii, unicodeBytes);
这篇关于不同的文件大小C ++到C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!