---
title: "VS2015,UNICODE字符集下printf,cout打印CString,与TRACE输出调试"
author: "kiolp"
date: "2016-08-24T23:44:15Z"
tags: []
categories: ["非技术"]
slug: "vs2015-unicode-printf-cout-cstring-trace"
draft: false
lastmod: "2016-08-24T23:44:15Z"
id: 2320020
url: "https://kiolp.iteye.com/blog/2320020"
---

下面的测试在中文电脑上"chs"直接使用""替换亦可.

CString Str;

 

 

```
#include <locale.h>                   // setlocale函数的头文件
setlocale(LC_ALL, "chs");             // 必加 只有添加这一句下面的打印1,2与调试1,2才能成功
wprintf(L"%s\r\n", Str.GetString());  // VC打印方式1
printf("%S\r\n", Str.GetString());    // 标准C打印方式2
TRACE(L"%s\r\n", Str.GetString());    // MFC调试方式1
TRACE("%S\r\n", Str.GetString());     // MFC调试方式2

#include <iostream>                   // VC++ wcout 头文件
wcout.imbue(locale("chs"));           // 必加 只有加上这一句下面的VC++方式打印才能成功
wcout <<Str.GetString() << endl;      // VC++方式打印(仅限VC)
```