VC++查错

来源:百度知道 编辑:UC知道 时间:2024/05/15 02:07:15
#include <stdio.h>
main()
{
int a;
double x;
float f=3.140000;
char c;
printf("please print 100,23.5");
scanf("%d%c",&a,&x);
printf("please print M");
getchar("%c",&c);
printf("int a=%d\n,double x=%f\n,flout f=%f\n",a,x,f);
putchar("char c=%c\n",c);
}
错误 是 D:\B07050530\expl_2.cpp(13) : error C2664: '_flsbuf' : cannot convert parameter 1 from 'char [11]' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast

怎么改

#include <stdio.h>
void main()
{
int a;
double x;
float f=3.140000;
char c;
printf("please print 100,23.5");
scanf("%d%c",&a,&x);
printf("please print M");
c = getchar(); //getchar函数正确用法是这样的
printf("int a=%d\n,double x=%f\n,flout f=%f\n",a,x,f);
putchar(c); //putchar函数只有一个参数
}

类型错误

无法从 char 转化为 int

c=int(c);
c = getchar();

char型转int
加个int temp = c - '0';
好了 用temp这个变量究行了