在写作之后,每个角色都会有额外的空间来临。怎么解决 [英] while writing, after every character additional space is coming. How to solve
问题描述
int dataSize1 = subNumber.GetLength();
subtitleNewFile.Write(subNumber,dataSize1);
subtitleNewFile.Write(\\\\ n,2);
subtitleNewFile.Close();
输出:亿人2 8州
感谢高级。
从调试器开始。
在线上放置一个断点:
subtitleNewFile.Write(subNumber,dataSize1);并运行你的应用程序。当它到达断点时,开始查看变量
subNumber
和dataSize1
中的确切内容 - 这应该会给你一个确切地说明你要写入文件的确切值。如果您知道这一点,就可以开始查看文件内容与文件内容不符的原因。
如果调试器中的长度显示为24,那么在字符串中没有多余的空格,那么你需要仔细查看你如何检查文件内容,然后在subtitleNewFile
类中找出你有什么内容当你创建流时它。
我们不能为你做任何事情!
可能你有在项目常规配置设置中使用Unicode Charater Set 。这样,CString
将保存2个字节的字符。
如果要将单字节(ANSI)字符串写入文件,请更改应用程序在写入文件之前设置或转换CString内容(例如,参见将CString转换为const char * [ ^ 一>]。
int dataSize1 = subNumber.GetLength(); subtitleNewFile.Write(subNumber,dataSize1); subtitleNewFile.Write("\r\n" ,2 ) ; subtitleNewFile.Close();
Output : b i l l i o n P e o p l e 2 8 s t a t e s
Thanks in advanced.
Start with the debugger.
Put a breakpoint on the line:
subtitleNewFile.Write(subNumber,dataSize1);And run your app. When it hits the breakpoint, start looking at exactly what is in the variables
subNumber
anddataSize1
- that should give you a clue as to exactly what values you are trying to write to the file. When you know that, you can start looking at exactly why the file content is not what you expected.
If the length is showing in the debugger as 24, and there are no extraneous spaces in the string, then you need to look at exactly how you are checking the file content, and then at thesubtitleNewFile
class to find out what you have doe to it when you created the stream.
We can't do any of that for you!
Possibly you have "Use Unicode Charater Set" in your project general configuration setting. This way aCString
would hold 2-byte characters.
If you want to write single byte (ANSI) strings to your file either change your application character set or convert your CString content before writing to the file (see, for instance "Convert CString to const char*"[^].
这篇关于在写作之后,每个角色都会有额外的空间来临。怎么解决的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!