格式化输出中的%s和%S的陷阱
2015-05-03 18:23
148 查看
CStringA csa;
CStringA csc;
CString csb(L"131231111111");
csa.Format("%s", csb); // 只会输出1
csc.Format("%S", csb); // 会输出131231111111
printf("%s\n", csa.GetBuffer(0));
printf("%s\n", csc.GetBuffer(0));
本意想输出131231111111,可是"%s"只会输出1,因为%s是按照ascill编码,而csb是unicode编码,unicode编码格式是一个"1"后会跟一个0x00,所以对于ascill来说,就认为字符串终止了.
%s和%S在不同的环境下,含义不一样:
CStringA csc;
CString csb(L"131231111111");
csa.Format("%s", csb); // 只会输出1
csc.Format("%S", csb); // 会输出131231111111
printf("%s\n", csa.GetBuffer(0));
printf("%s\n", csc.GetBuffer(0));
本意想输出131231111111,可是"%s"只会输出1,因为%s是按照ascill编码,而csb是unicode编码,unicode编码格式是一个"1"后会跟一个0x00,所以对于ascill来说,就认为字符串终止了.
%s和%S在不同的环境下,含义不一样:
s | When used with printf functions, specifies a single-byte–character string; when used with wprintf functions, specifies a wide-character string. Characters are printed up to the first null character or until the precision value is reached |
S | When used with printf functions, specifies a wide-character string; when used with wprintf functions, specifies a single-byte–character string. Characters are printed up to the first null character or until the precision value is reached. |
相关文章推荐
- 格式化输出中的%s和%S的陷阱
- 格式化输出%s和%S的区别
- 关于printf系列格式化输出函数,%S格式的分析
- Python格式化输出%s和%d
- %s格式化输出
- Python 格式化输出 —— %r 与 %s 的区别(__repr__ 与 __str__)
- Python格式化输出%s和%d
- 格式化输出中的%s和%S的区别
- Python格式化输出%s和%d
- Python格式化输出%s和%d
- Python3.3 print函数用法,print 格式化输出
- VC++格式化输入输出
- 数组的格式化输出
- C语言格式化输出总结
- 帮助你格式化console.log输出的javascript类库 - Log
- Java 输出文件通过 BufferedWriter.newline() 方法换行的陷阱
- JSTL、JAVA将浮点数字输出格式化
- C语言格式化输出(整理2)
- Objective-C中的字符串格式化输出(转载)
- PowerShell 2.0解析、格式化及显示远程输出