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

字號(hào):


    今天在研究VC++ 使用 ADO 讀取MS SQKSERVER 數(shù)據(jù)庫(kù)時(shí), 發(fā)現(xiàn):
    string ansi字符串
    wstring unicode字符串
    _bstr_t com字符串
    之間的轉(zhuǎn)換關(guān)系,示例如下:
    // ex_02_wstring_cv_string.cpp : 定義控制臺(tái)應(yīng)用程序的入口點(diǎn)。
    //
    #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"春如舊,人空瘦,淚痕紅浥鮫綃透。桃花落,閑池閣,山盟雖在,錦書(shū)難托。莫、莫、莫。";