错误字符串和字符 [英] error string and char..
本文介绍了错误字符串和字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
float c,f;
printf("plesase write a number of degrees celsius:");
scanf("%f",&c);
f=c*9/5+32;
printf("number of degree fahrenheit: %f\n",f);
system("pause");
return 0;
}
输出是数字,输入是数字.
如果输入字符串,则输出不适合,例如,如果输入字符串,则我们cout的输出<<"error";
使用cin和cout是什么?
Output is the number.Its input is the number.
If the input string, the output is not suitable for, say, if the input string, the output of our cout<<"error";
With cin and cout What is it?
推荐答案
尝试以下操作:
Try this:
int main(int argc, char *argv[])
{
float c,f;
printf("plesase write a number of degrees celsius:");
if (scanf("%f",&c) != 1)
{
printf("Error\n");
}
else
{
f=c*9/5+32;
printf("number of degree fahrenheit: %f\n",f);
}
system("PAUSE");
return 0;
}
这篇关于错误字符串和字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文