宽字符到兆字节 [英] Wide Char To Multbyte

查看:70
本文介绍了宽字符到兆字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将结果打印到日志文件以及控制台中.在控制台屏幕上,一切都很好.日志文件不好.日志文件的示例.

来源IP:65.39.148.3400EBF5D000294844
2 URL:00407B00"

应该是
来源IP:65.39.148.34
1个网址:www.codeprojet.com
2网址:codeproject.com

该项目位于多字节"中
这是代码...

I''m printing results to a log file as well as to the console. All is fine on the console screen. The log file is not good. An example of the logfile.

"Source IP:65.39.148.3400EBF5D000294844
2 URL:00407B00"

it should be
Source IP:65.39.148.34
1 URL: www.codeprojet.com
2 URL: codeproject.com

The project is in Multi-Byte
Here is the code...

void PrintBrowserInfo(IWebBrowser2 *pBrowser) {
	BSTR bstr;
 	pBrowser->get_LocationURL(&bstr);
	wprintf(L"\n  1 URL: %s\n\n", bstr);
	myfile << "\n   1 URL:" << bstr;
	std::wstring wsURL;
	wsURL = bstr;
 	
	size_t DSlashLoc = wsURL.find(L"://");
	if (DSlashLoc != wsURL.npos)
		{
		wsURL.erase(wsURL.begin(), wsURL.begin() + DSlashLoc + 3);
		}
	DSlashLoc = wsURL.find(L"www.");
	if (DSlashLoc == 0)
		{
		wsURL.erase(wsURL.begin(), wsURL.begin() + 4);
		}
	
	wprintf(L"\n   2 URL: %s\n\n", wsURL.c_str());
	myfile << "\n   2 URL:" << wsURL.c_str();
	SysFreeString(bstr);
}



我尝试这样做...

myfile<< L"\ n 2 URL:"<< wsURL.c_str();
它没有产生正确的结果.



I tried doing this...

myfile <<L "\n 2 URL:" << wsURL.c_str();
It did not produce the correct results.

推荐答案

直接将BSTR发送给插入运算符会导致此问题,因为它不是可识别的类型.将其转换为正确的字符指针,它应该可以工作.请注意,(假设myfileofstream的实例,则不存在接受宽字符串的重载,如 ^ ].
Sending the BSTR direct to the insertion operator is causing you this problem since it is not a recognised type. Convert it to a proper character pointer and it should work. Note that (assuming myfile is an instance of ofstream that there is no overload that accepts a wide string, as seen here[^].


这篇关于宽字符到兆字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆