这是我的C++代码。你如何显示浮点数?
#include <iostream>
#include <string.h>
#include <ctype.h>
#include <stdio.h>
int main()
{
FILE *f1;
char c;
int num[100], tokenvalue = 0, i = 0, j = 0;
f1 = fopen("test.txt", "r");
while ((c = getc(f1)) != EOF)
{
if (isdigit(c))
{
tokenvalue = c - '0';
c = getc(f1);
while (isdigit(c))
{
tokenvalue = tokenvalue * 10 + (c - '0');
c = getc(f1);
}
num[i++] = tokenvalue;
ungetc(c, f1);
}
}
printf("\nThe no's in the program are\n");
for (j = 0; j < i; j++)
{
printf("%d", num[j]);
printf("\n");
}
int z;
scanf("%d", &z);
return 0;
}
我test.txt的输入文件有:
Name: Md. Jakir Hossin
Age: 23
Name: Shafi Mahmud
Age: 18.5
Name: Asmaul Husna
Age: 28
Name: Md. Jahirul Haque
Age: 30.4
输出:
[输出] [1]
该程序显示任何整型数字,但不显示浮点数。你如何显示浮点数?
用户'%f'作为格式说明符 – 2014-10-20 04:10:34
为什么在C++代码中使用stdio(标记为这样)。它是C代码 – 2014-10-20 04:11:01
@EdHeal还有数百人不知道区别/认为C++是更高版本的c:D – 2014-10-20 04:12:19