cin>> will check digit or other string automatically but cin.get don't check it
#include<iostream>
using namespace std;
int main()
{
char one_char,decimal_point,digit1,digit2;
long dollars;
bool negative;
cin>>one_char;
if(one_char == '-')
{
negative = true;
cin >> one_char;
}
else
{
negative=false;
}
cin>>dollars>>decimal_point>>digit1>>digit2;
cout<< dollars <<" "<<decimal_point <<" "<<digit1<< " " <<digit2<<endl;
}
static_cast<int>(v_char)-static_cast<int>('0'); --return cast char to int
operator + or - or other applay a class instance+20 must be let os known how the 20 add the instance
first check operator fail then call instructor implicitly
ostream & operator<<(ostream & outs ,const class& cs)
big three copy constructor 、operator equal and destructor
unnamed namespace {} is local to compilation unit. global namespace
#include<iostream>
using namespace std;
int main()
{
char one_char,decimal_point,digit1,digit2;
long dollars;
bool negative;
cin>>one_char;
if(one_char == '-')
{
negative = true;
cin >> one_char;
}
else
{
negative=false;
}
cin>>dollars>>decimal_point>>digit1>>digit2;
cout<< dollars <<" "<<decimal_point <<" "<<digit1<< " " <<digit2<<endl;
}
static_cast<int>(v_char)-static_cast<int>('0'); --return cast char to int
operator + or - or other applay a class instance+20 must be let os known how the 20 add the instance
first check operator fail then call instructor implicitly
ostream & operator<<(ostream & outs ,const class& cs)
big three copy constructor 、operator equal and destructor
unnamed namespace {} is local to compilation unit. global namespace
本文探讨了C++中使用cin进行数据读取的方法,包括如何处理负数及小数点后的数字,并介绍了类型转换和运算符重载的概念。
202

被折叠的 条评论
为什么被折叠?



