在sprintf中接收错误 [英] Receiving Error in sprintf

查看:63
本文介绍了在sprintf中接收错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下命令在VS 2005中获取语法错误....



int sprintf((char *)cptr,const char * format [cOutBuffer [usLoop] ]]);

The following command getting a syntax error in VS 2005....

int sprintf((char *)cptr,const char *format[cOutBuffer[usLoop]]);

推荐答案

第一点 - 很好地告诉我们这是一个语法错误:任何其他线索/上下文?



第二点 - 除非你正在进行一些非常难以实现的固定字段格式化,而iostreams不会用驳船杆触摸sprintf,而是使用std :: stringstream。



第三点 - 我非常谨慎地将const转换出来(我认为你正在使用缺少任何其他上下文的第一个参数)。如果你已经在你的程序中的某个地方声明了cptr const,那么大概是出于某种原因 - 即它指向了一些不可改变的东西。擦除这种保护有点愚蠢。



第四点 - 你的第二个参数看起来像一个指向char的指针数组的声明,它不是一个变量名。这可能是导致编译器在抽搐堆中摔倒的原因。
First point - great telling us it's a syntax error: Any other clues/context?

Second point - unless you're doing some fixed field formatting that's really difficult to achieve with iostreams don't touch sprintf with a barge pole, use std::stringstream instead.

Third point - I'd be really wary of casting const away (which I presume you're doing with the first parameter lacking any other context). If you've declared cptr const somewhere else in your program it was presumably for a reason - i.e. it was pointing to something immutable. Scrubbing that protection is a bit daft.

Fourth point - your second parameter looks like a declaration of an array of arrays of pointers to char, it's not a variable name. That's probably what's causing the compiler to fall over in a twitching heap.


hi,

尝试这样

int myVariable = sprintf ((char *)cptr,const char * format [cOutBuffer [usLoop]]);



希望这有助于

try like this
int myVariable = sprintf((char *)cptr,const char *format[cOutBuffer[usLoop]]);

hope this helps


这篇关于在sprintf中接收错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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