wstring需要显示初始化

wstring m_wstrPointName;

CMyPoint::CMyPoint(int pointID):m_pointID(pointID),m_wstrPointName(L"")
{
	m_nX=100;
	m_nY=100;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在osgEarth中显示中文需要使用到中文字体文件,以及将中文字符串转换为utf-8编码。下面是一个简单的示例代码,可以实现在osgEarth中显示中文: ```cpp #include <osgEarth/MapNode> #include <osgEarth/AnnotationNode> #include <osgEarth/Registry> #include <osgEarthAnnotation/PlaceNode> int main( int argc, char** argv ) { // 初始化osgEarth osg::ref_ptr<osgEarth::MapNode> mapNode = osgEarth::MapNode::create(); osg::ref_ptr<osgEarth::AnnotationNode> annoNode = new osgEarth::AnnotationNode(mapNode->getMap()); // 创建中文字体文件 osg::ref_ptr<osgText::Font> font = osgText::readFontFile("simhei.ttf"); // 创建中文字符串 std::string str = "你好,世界!"; std::wstring_convert<std::codecvt_utf8<wchar_t>> conv; std::wstring wstr = conv.from_bytes(str); // 将中文字符串转换为utf-8编码 std::string utf8str; for (wchar_t ch : wstr) { if (ch < 0x80) { utf8str.push_back(static_cast<char>(ch)); } else if (ch < 0x800) { utf8str.push_back(static_cast<char>((ch >> 6) | 0xC0)); utf8str.push_back(static_cast<char>((ch & 0x3F) | 0x80)); } else { utf8str.push_back(static_cast<char>((ch >> 12) | 0xE0)); utf8str.push_back(static_cast<char>(((ch >> 6) & 0x3F) | 0x80)); utf8str.push_back(static_cast<char>((ch & 0x3F) | 0x80)); } } // 创建PlaceNode并显示中文字符串 osg::ref_ptr<osgEarth::Annotation::PlaceNode> placeNode = new osgEarth::Annotation::PlaceNode(mapNode->getMap(), osgEarth::GeoPoint(), utf8str, font.get()); annoNode->addChild(placeNode); // 显示场景 osgViewer::Viewer viewer; viewer.setSceneData(annoNode.get()); return viewer.run(); } ``` 在上面的代码中,我们使用了 `std::wstring_convert` 类将中文字符串转换为 `std::string` 类型的 utf-8 编码。然后创建了一个 `PlaceNode` 对象,并将其添加到 `AnnotationNode` 子节点中,从而实现在osgEarth中显示中文的功能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值