Unicode下 LPCTSTR 转 string

最近因工作需要,将原有多字节项目转到Unicode编码。状况百出,特此记录。

LPCTSTR uIp = _T("127.0.0.1");

string ip = LPSTR(uIp);

输出是多少?是 1,没错,就是1

怎么解决,用此宏->CW2A 请看下文测试过程。


// UnicodeTest.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include
#include
#include
using namespace std;


void F(LPCTSTR rhs)
{
    string ip = (LPSTR)rhs;
    cout << ip <
}

int _tmain(int argc, _TCHAR* argv[])
{

    LPCTSTR uIp = _T("127.0.0.1");
    string ip = LPSTR(uIp);
    cout <
    F(uIp);

    ip = CW2A(uIp);
    cout << ip.data() <

    return 0;
}



可以看到,经过CW2A,最终输出127.0.0.1.而直接用LPSTR转输出为1




你可能感兴趣的:(C++)