std::map的问题?

yueyucanyang 2008-07-13 02:04:30
我在别人的博客上看到这样的一个例子。是用来现显示字符的!
下面的是头文件
// WGLUTFont.h: interface for the CWGLUTFont class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_WGLUTFONT_H__D1FC606E_2402_48ED_B6EC_CB2775FFAC29__INCLUDED_)
#define AFX_WGLUTFONT_H__D1FC606E_2402_48ED_B6EC_CB2775FFAC29__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <gl\gl.h> // Header File For The OpenGL32 Library
#include <gl\glu.h> // Header File For The GLu32 Library
#include <gl\glaux.h> // Header File For The Glaux Library
#include <map>
#include <string>



typedef std::map<int ,std::string> FontMap;

class CWGLUTFont
{

protected:
HWND m_hWnd; // 关联窗口

FontMap m_mapText; // 2D字体Map
FontMap m_mapGlyph; // 3D字体Map

BOOL m_bLoadFont; // 字体加载标记


};

#endif // !defined(AFX_WGLUTFONT_H__D1FC606E_2402_48ED_B6EC_CB2775FFAC29__INCLUDED_)

部分实现文件
// CWGLUTFont.cpp: implementation of the CCWGLUTFont class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "uwtnetsim.h"
#include "WGLUTFont.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif




/******************************************************************************

函数名: PreLoadASCII
输 入: bPreLoadAscii --- 是否预加载ASCII码(256个)
输 出: 无
返回值: 失败返回FALSE
功 能: 预加载2D ASCII字符
说 明: 请在系统建立后再加载
ASCII码预加载只限于2D文本,这里假设程序不使用3D文本
******************************************************************************/

BOOL CWGLUTFont::PreLoadASCII()
{
// 预加载ASCII码
BOOL bResult;
GLuint base;
int i;

HDC hDC = wglGetCurrentDC();

ASSERT(hDC != NULL);

base = glGenLists(256);

bResult = wglUseFontBitmaps(hDC, 0, 255, base);

if(!bResult)
{
return FALSE;
}

for(i = 0; i < 256; i++)
{
m_mapText.insert(FontMap::value_type(i, base+i));
}

base = glGenLists(256);

GLYPHMETRICSFLOAT agmf[256];
bResult = wglUseFontOutlines(hDC, 0, 255, base, 0.0f, 0.1f,
WGL_FONT_POLYGONS, agmf);

for(i = 0; i < 256; i++)
{
m_mapGlyph.insert(FontMap::value_type(i, base+i));
}

return TRUE;
}


/******************************************************************************

函数名: PreLoadText
输 入: szString --- 要预加载的字符串
nCount --- 要预加载的字符串长度
-1表示加载整个字符串(要求以\0结束)
输 出: 无
返回值: 失败返回FALSE
功 能: 预加载2D字符串
说 明: 预加载的字符串在显示时速度较快(相当于Cache)
******************************************************************************/

BOOL CWGLUTFont::PreLoadText(LPCTSTR szString, INT nCount /* = -1 */)
{
int r;
int nNum;
GLuint nList;
BOOL bResult;
HDC hDC = wglGetCurrentDC();

if(!szString)
{
return FALSE;
}

if(nCount == -1)
{
nNum = _tcslen(szString);
}
else
{
nNum = nCount;
}

for(r = 0; r < nNum; r++)
{
if(m_mapText.find(szString[r]) != m_mapText.end())
{
// 字符已经存在于列表中
continue;
}

nList = glGenLists(1);
bResult = wglUseFontBitmaps(hDC, szString[r], 1, nList);

if(!bResult)
{
return FALSE;
}

m_mapText.insert(FontMap::value_type(szString[r], nList));
}

return TRUE;
}


/******************************************************************************

函数名: PreLoadGlyph
输 入: szString --- 要预加载的字符串
nCount --- 要预加载的字符串长度
-1表示加载整个字符串(要求以\0结束)
输 出: 无
返回值: 失败返回FALSE
功 能: 预加载3D字符串
说 明: 预加载的字符串在显示时速度较快(相当于Cache)
******************************************************************************/

BOOL CWGLUTFont::PreloadGlyph(LPCTSTR szString, INT nCount /* = -1 */)
{
int r;
int nNum;
GLuint nList;
BOOL bResult;
HDC hDC = wglGetCurrentDC();
GLYPHMETRICSFLOAT pgmf[1];

if(!szString)
{
return FALSE;
}

if(nCount == -1)
{
nNum = _tcslen(szString);
}
else
{
nNum = nCount;
}

for(r = 0; r < nNum; r++)
{
if(m_mapGlyph.find(szString[r]) != m_mapGlyph.end())
{
// 字符已经存在于列表中
continue;
}

nList = glGenLists(1);
bResult = wglUseFontOutlines(hDC, szString[r], 1, nList,
0.0f, 0.1f, WGL_FONT_POLYGONS, pgmf);

if(!bResult)
{
return FALSE;
}

m_mapGlyph.insert(FontMap::value_type(szString[r], nList));
}

return TRUE;
}


可是我在编译的时候会出现问题,那位能帮助解决一下?
编译连接出现的问题为:

E:\only code\pj\UwtNetSim\WGLUTFont.cpp(206) : error C2665: 'pair<int const ,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >::pair<int const ,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >' : none of the 2 overloads can convert parameter 2 from type 'unsigned int'




...全文
2165 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Crob 2008-07-14
  • 打赏
  • 举报
回复
错误信息中已经说得很清楚了
你的类型是 typedef std::map <int ,std::string> FontMap;
而你放了一个unsigned int进去。
yueyucanyang 2008-07-14
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 Crob 的回复:]
错误信息中已经说得很清楚了
你的类型是 typedef std::map <int ,std::string> FontMap;
而你放了一个unsigned int进去。
[/Quote]
那我要修改typedef std::map <int ,std::string> FontMap; 来适应程序了!
因为我下载的源程序这个部分是不正确的,typedef std::map <int ,std::string> FontMap;
是我自己写的!
cnzdgs 2008-07-13
  • 打赏
  • 举报
回复
编译错误尽量自己解决,如果自己看不出错误原因,就把出错的行标注出来,并把错误信息贴全。

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧