stringwstring_bstr_t的互相转换

2014-10-22 09:30:04 · 作者: · 浏览: 71

  今天在研究VC++ 使用 ADO 读取MS SQKSERVER 数据库时, 发现:


  string ansi字符串


  wstring unicode字符串


  _bstr_t com字符串


  之间的转换关系,示例如下:


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


  //


  #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"春如旧,人空瘦,泪痕红 鲛绡透。桃花落,闲池阁,山盟虽在,锦书难托。莫、莫、莫。";