请教关于在c++项目中gcvt的用法

causlayer 2010-05-18 01:50:21
char actualString[255];

CSTR& CSTR::operator+(double number){
char temp [20];
_gcvt_s (number,10,temp,9);
strcat_s (this->actualString,temp);
return g_strString;
}
这里的_gcvt_s我还用了gcvt和gcvt_s调试,都不行
用gcvt的结果是:warning C4996: 'gcvt': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _gcvt. See online help for details.
_gcvt的结果是:warning C4996: '_gcvt': This function or variable may be unsafe. Consider using _gcvt_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
_gcvt_s需要四个参数,加粗部分是我最后加的报错结果是:error C2664: “errno_t _gcvt_s(char *,size_t,double,int)”: 不能将参数 1 从“double”转换为“char *”
我用是vs2008,字符集选了unicode和多字符集结果是相同的.

请各位高手帮忙,谢谢.
...全文
1086 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
causlayer 2010-05-18
  • 打赏
  • 举报
回复
请问如何格式化啊,能给一个完整的代码吗
我刚看了点最基础的c++,看不明白了.谢谢
Eleven 2010-05-18
  • 打赏
  • 举报
回复
errno_t _gcvt_s(
char *buffer,
size_t sizeInBytes,
double value,
int digits
);
第一个参数char*,你把你的number格式化一下char[]再传入
char buf[20];
sprintf_s(buf, sizeof(buf), "%f", number);
..
_gcvt_s(buf, ....);
causlayer 2010-05-18
  • 打赏
  • 举报
回复
另外我刚看了一下,我下的dircet的sdk是9.11.519,我把#define DIRECTINPUT_VERSION 0x0700
改成了#define DIRECTINPUT_VERSION 0x0911,可还是报错.
causlayer 2010-05-18
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 oldn_cc_bird 的回复:]
- -寒..
[/Quote]
高手,这是什么意思啊
oldn123 2010-05-18
  • 打赏
  • 举报
回复
- -寒..
causlayer 2010-05-18
  • 打赏
  • 举报
回复
谢谢,可我是从拷贝的别人的代码,我是新手,请帮忙修改啊
这个头文件太长了,我拷贝了有错误的这一段
其中有一些地方我已经按照提示做了修改.
//-----------------------------------------------------------------------------
// DIRECTX LIBRARY
// This include file contains functions that access Direct X.
// By Patrick Lester, pwlester@policyalmanac.org

// You also will need the Direct X 7.0 SDK, and to install the lib
// and include files from the SDK to your C++ lib and include
// folders. You can get the DirectX 7.0 SDK (large!) here:
// http://download.microsoft.com/download/win98SE/SDK/7.0/W9X/EN-US/dx7sdk-700.1.exe
//-----------------------------------------------------------------------------

#include <ddraw.h> //Direct Draw header
#define DIRECTINPUT_VERSION 0x0700
#include <dinput.h>
#include <tchar.h>
#define D3D_OVERLOADS
#include <d3d.h>
#include <string> //used by Debuglog


//-----------------------------------------------------------------------------
// Name: Function prototypes (where needed)
//-----------------------------------------------------------------------------
DWORD ColorMatch(LPDIRECTDRAWSURFACE7 pdds, COLORREF rgb);
HRESULT LoadPalette(LPDIRECTDRAWPALETTE* ppPalette,const TCHAR* strBMP );
int ReleaseObjects(void);
static HRESULT CALLBACK TextureSearchCallback(DDPIXELFORMAT* pddpf, VOID* param);
void UpdateMouse (void);
void Debuglog (char* pDebuglog);
void Debuglog (int number);
int SetBrush (int r, int g, int b, int pattern=0, int style=0);
int SetFontColor(int r,int g,int b);
int SetPen (int r, int g, int b, int thickness=1, int style=0);



//-----------------------------------------------------------------------------
// Name: Class Declarations
//-----------------------------------------------------------------------------
class cImage //class containing info about an image
{
public:
LPDIRECTDRAWSURFACE7 pSurface; //pointer to the image
int imageWidth;
int imageHeight;
int xHandle;
int yHandle;
bool isMasked; //0 = no, 1 = yes
int convertedMaskColor;//mask color converted to used pixel format
byte memLocation; //0 = VRAM, 1 = RAM
bool imageIs3D; //0 = false, 1 = true

cImage* previousImage;//pointer to previous item in linked list
cImage* nextImage;//pointer to next item in linked list

//constructor member function
cImage()
{
previousImage = NULL;
nextImage = NULL;
}
};


//Concatening string class, CSTR: This class is used to combine
//strings and numbers into a single, usable string for the
//Debuglog and Text commands.
#define combine g_strString-
class CSTR
{
public:
char actualString[255];
CSTR& operator-(char* nextString);
CSTR& operator-(int number);
CSTR& operator-(double number);
CSTR& operator+(char* nextString);
CSTR& operator+(int number);
CSTR& operator+(double number);
};
CSTR g_strString; //declare global CSTR

CSTR& CSTR::operator-(char* nextString){
strcpy_s (this->actualString,nextString);
return g_strString;
}

CSTR& CSTR::operator-(int number){
char temp [33];
_itoa_s (number,temp,10);
strcpy_s (this->actualString,temp);
return g_strString;}

CSTR& CSTR::operator-(double number){
char temp [20];
gcvt (number,10,temp);
strcpy_s (this->actualString,temp);
return g_strString;}

CSTR& CSTR::operator+(char* nextString){
strcat_s (this->actualString,nextString);
return g_strString;}

CSTR& CSTR::operator+(int number){
char temp [33];
_itoa_s (number,temp,10);
strcat_s (this->actualString,temp);
return g_strString;}

CSTR& CSTR::operator+(double number){
char temp [20];
gcvt (number,10,temp);
strcat_s (this->actualString,temp);
return g_strString;}

void Debuglog (CSTR pStringDebuglog);
oldn123 2010-05-18
  • 打赏
  • 举报
回复
你参数传的不对
函数原型:
errno_t _gcvt_s(
char *buffer,
size_t sizeInBytes,
double value,
int digits
);

char temp [20];
_gcvt_s (temp,20, number,9);
causlayer 2010-05-18
  • 打赏
  • 举报
回复
我把temp和number换个位置,是能编译了.可问题又出来了
1>------ 已启动生成: 项目: NewAstar, 配置: Debug Win32 ------
1>正在链接...
1>main.obj : error LNK2019: 无法解析的外部符号 __imp__timeGetTime@0,该符号在函数 "int __cdecl FPS(void)" (?FPS@@YAHXZ) 中被引用
1>main.obj : error LNK2001: 无法解析的外部符号 _IID_IDirect3DRGBDevice
1>main.obj : error LNK2001: 无法解析的外部符号 _IID_IDirect3DHALDevice
1>main.obj : error LNK2001: 无法解析的外部符号 _IID_IDirect3D7
1>main.obj : error LNK2001: 无法解析的外部符号 _c_dfDIMouse
1>main.obj : error LNK2001: 无法解析的外部符号 _GUID_SysMouse
1>main.obj : error LNK2001: 无法解析的外部符号 _IID_IDirectInputDevice7A
1>main.obj : error LNK2019: 无法解析的外部符号 _DirectInputCreateEx@20,该符号在函数 "int __cdecl Graphics(int,int,int,struct HWND__ *,char *)" (?Graphics@@YAHHHHPAUHWND__@@PAD@Z) 中被引用
1>main.obj : error LNK2001: 无法解析的外部符号 _IID_IDirectInput7A
1>main.obj : error LNK2019: 无法解析的外部符号 _DirectDrawCreateEx@16,该符号在函数 "int __cdecl Graphics(int,int,int,struct HWND__ *,char *)" (?Graphics@@YAHHHHPAUHWND__@@PAD@Z) 中被引用
1>main.obj : error LNK2001: 无法解析的外部符号 _IID_IDirectDraw7
1>MSVCRTD.lib(crtexe.obj) : error LNK2019: 无法解析的外部符号 _main,该符号在函数 ___tmainCRTStartup 中被引用
1>D:\Program Files\Microsoft Visual Studio 9.0\Visual Studio 2008\Projects\NewAstar\Debug\NewAstar.exe : fatal error LNK1120: 12 个无法解析的外部命令
1>生成日志保存在“file://d:\Program Files\Microsoft Visual Studio 9.0\Visual Studio 2008\Projects\NewAstar\NewAstar\Debug\BuildLog.htm”
1>NewAstar - 13 个错误,0 个警告
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
causlayer 2010-05-18
  • 打赏
  • 举报
回复
CSTR& CSTR::operator-(double number){
char temp [20];
sprintf_s(temp, sizeof(temp), "%f", number);
_gcvt_s (number,10,temp,9);
strcpy_s (this->actualString,temp);
return g_strString;}
是这么写吗?可还是输出同样的错误

16,550

社区成员

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

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

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