std::map的问题?
我在别人的博客上看到这样的一个例子。是用来现显示字符的!
下面的是头文件
// 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'