简单的快乐着~
还真没有遇到过这样的问题呢?LZ有想发.不错.先顶起来看看.等高人来.
#include<iostream>
#include<cstring>
#include<iomanip>
using namespace std;
main()
{
cout<<"insert a string:"<<endl;
char a;
int sum=0;
int sign=1;
cin>>a;
while(a!='#')
{
a-=0x30;
if((0x1<=a)&&(a<=0x9))
{
sum*=10;
sum+=a;
}
else
{
cout<<"the string is a charstring!"<<endl;
sign=0;
break;
}
cin>>a;
}
if(sign)
cout<<"the string is a number= :"<<sum<<endl;
}
不知道你说的是这个意思不?
我定义了一个共用体,
#include <stdio.h>
union number
{
double d;
char s[64];
}num;
union number select();
void main()
{
select();
}
union number select()
{
printf("please input any thing !\n");
if(scanf("%lf",&num.d))
printf("this is a number:%lf\n",num.d);
else
{
gets(num.s);
printf("this is a string:%s\n",num.s);
}
return num;
}