#include "stdafx.h"
#include <iostream>
#include <string>
#include <sstream>
#include <cassert>
#include <conio.h>
using namespace std;
void main()
{
cout << "请输入数字:" << flush;
double earnings = 0.0;
{ // 不是数字,或不是第一个小数点就不显示;而且必须有输入才可以继续
string temp;
bool dot = false;
for( char c; c=(char)_getch(), c!='\r' || temp.empty(); ) // 这里面有个逗号表达式,不要把它当成分号
{
if( ( c>='0' && c<='9' ) || (c=='.' && !dot && (dot=true)) ) // "&& (dot=true)" 没有写错,我这是个取巧做法
{
putch( c );
temp += c;
}
}
istringstream is( temp );
is >> earnings;
assert( is.eof() );
cout << endl;
}
cout << "你输入的是:" << earnings << endl;
cin.get();
}