2017年計算機等級考試二級C++輔導(dǎo):stringwstring_bstr_t的互相轉(zhuǎn)換

字號:


    今天在研究VC++ 使用 ADO 讀取MS SQKSERVER 數(shù)據(jù)庫時, 發(fā)現(xiàn):
    string ansi字符串
    wstring unicode字符串
    _bstr_t com字符串
    之間的轉(zhuǎn)換關(guān)系,示例如下:
    // ex_02_wstring_cv_string.cpp : 定義控制臺應(yīng)用程序的入口點。
    //
    #include "stdafx.h"
    #include "string"
    #include "icrsint.h"
    #include "comutil.h"
    using namespace std;
    #import "C:\\Program Files\\Common Files\\System\\ADO\\msado15.dll" no_namespace rename("EOF", "EndOfFile")
    int _tmain(int argc, _TCHAR* argv[])
    {
    CoInitialize(NULL);
    wstring ws1,ws2;
    ws2 = L"春如舊,人空瘦,淚痕紅浥鮫綃透。桃花落,閑池閣,山盟雖在,錦書難托。莫、莫、莫。";