赞
踩
printf函数配合%s占位符输出字符串类结果是乱码。
- #include <iostream>
- #include <string.h>
- using namespace std;
-
- int main()
- {
- string name = "uzi";
- printf("name=%s\r\n", name);
-
-
-
- system("pause");
- return 0;
- }
输出结果:
解决方法:
- #include <iostream>
- #include <string.h>
- using namespace std;
-
- int main()
- {
- string name = "uzi";
- /*printf("name=%s\r\n", name);*/
-
- printf("name=%s;\r\n", (name).c_str());
-
-
-
- system("pause");
- return 0;
- }
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
验证结果:
原理是啥?有知道的的麻烦评论区告知下声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。