int sprintf_s (char *,size_t,const char *,...) ": cannot convert parameter 2 from" const char [3] "to" size_t "

Source: Internet
Author: User

2014-03-02 20:14The following error occurred while compiling the following code:
CPP: Error C2664: "int sprintf_s (char *,size_t,const char *,...)": cannot convert parameter 2 from "const char [3]" to "size_t"
What does this mean, please? How do I change it?
#include <iostream>
#include <string>
#include <stdio.h>
using namespace Std;
String Dec_to_hex (double);
int main () {
Double X;
String str;
cout<< "Please input a decimal number:\n";
cin>>x;
Str=dec_to_hex (x);
cout<<str;
}
String Dec_to_hex (Double x) {
char* CH[20];
String str,str1;
int N=int (x), Num,count;
Double m=x-n;
while (n) {
count=0;
num=n%16;
N=N/16;
sprintf_s (Ch[count], "%x", num);
count++;
}
for (unsigned i=count;1>0;i--) {
Str.append (Ch[i-1]);
}
cout<<str<<endl;
return str;
}










Reply to discussion (solution) sprintf_s (ch[count],1, "%x", num), the second parameter is a secure version of the length unsigned int type sprintf_s () is sprintf (), avoiding sprintf by specifying the buffer length () Presence of overflow risk
The second parameter is size_t, which means that the maximum length of the buffer sprintf_s () is the secure version of sprintf () and avoids the risk of overflow by specifying the buffer length to avoid sprintf ()
The second parameter is size_t, which refers to the maximum length of the buffer
+1 got it! Thank you, everyone! Transferred from: http://www.itnose.net/detail/973571.html

int sprintf_s (char *,size_t,const char *,...) ": cannot convert parameter 2 from" const char [3] "to" size_t "

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.