c++学习cin的使用总结
cin属于istream类的对象(还没搞懂什么是类,c++萌新,大佬轻喷)
先说一下我为什么会写这篇博客:
下午照着c++primerplus做题的时候遇到一个难点,到网上找到答案之后发现
cin还有这么多用法`:
basic_istream& __CLR_OR_THIS_CALL operator>>(int& _Val) { // extract an int
static_assert(sizeof(int) == sizeof(long), "Bad overflow assumptions due to sizeof(int) != sizeof(long)");
long _Result = _Val;
_Common_extract_with_num_get(_Result);
_Val = _Result;
return *this;
}
basic_istream& __CLR_OR_THIS_CALL operator>>(unsigned int& _Val) { // extract an unsigned int
return _Common_extract_with_num_get(_Val);
}
basic_istream& __CLR_OR_THIS_CALL operator>>(long& _Val) { // extract a long
return _Common_extract_with_num_get(_Val);
}
basic_istream& __CLR_OR_THIS_CALL operator>>(unsigned long& _Val) { // extract an unsigned long
return _Common_extract_with_num_get(_Val);
}
basic_istream& __CLR_OR_THIS_CALL operator>>(long long& _Val) { // extract a long long
return _Common_extract_with_num_get(_Val);
}
basic_istream& __CLR_OR_THIS_CALL operator>>(unsigned long long& _Val) { // extract an unsigned long long
return _Common_extract_with_num_get(_Val);
}
basic_istream& __CLR_OR_THIS_CALL operator>>(float& _Val) { // extract a float
return _Common_extract_with_num_get(_Val);
}
basic_istream& __CLR_OR_THIS_CALL operator>>(double& _Val) { // extract a double
return _Common_extract_with_num_get(_Val);
}
basic_istream& __CLR_OR_THIS_CALL operator>>(long double& _Val) { // extract a long double
return _Common_extract_with_num_get(_Val);
}
basic_istream& __CLR_OR_THIS_CALL operator>>(void*& _Val) { // extract a void pointer
return _Common_extract_with_num_get(_Val);
}`
这些是我在头文件istreaml里面找到的,发现"<<"操作符和函数很类似,当输入符合参数类型的数据时,函数返回一个非零数,否则返回“0”。

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



