C++
SpursCLOUD
这个作者很懒,什么都没留下…
展开
-
类模板(函数模板)
#include using namespace std;templateT abs(T x) { return x < 0?-x:x;}int main() { int n = -5; double d = -5.5; cout<<abs(n)<<endl; cout<<abs(d)<<endl; return 0;}原创 2015-06-01 20:56:18 · 226 阅读 · 0 评论 -
palindrome number
#include using namespace std;bool pail(unsigned n) { unsigned i = n; unsigned m = 0; while(i > 0) { m = m*10+i%10; i /= 10; } return m == n;}int main() { unsigned m=0; do { cou原创 2015-06-06 00:45:21 · 291 阅读 · 0 评论 -
流类库与输入输出--对齐方式
#include #include #include using namespace std;int main() { double values[] = {1.23, 35.36, 653.7, 4358.24}; string names[] = {"Zoot", "Jimmy", "Al", "Stan"}; for(int i = 0; i < 4; i++) co原创 2015-06-06 21:40:37 · 391 阅读 · 0 评论 -
流类库与输入输出--精度
#include #include #include using namespace std;int main() { double values[] = {1.23, 35.36, 653.7, 4358.24}; string names[] = {"Zoot", "Jimmy", "Al", "Stan"}; for(int i = 0; i < 4; i++) co原创 2015-06-06 21:42:56 · 381 阅读 · 0 评论 -
输入输出控制
#include #include #include using namespace std;int main() { int values[] = {111, 123, 653, 43584}; string names[] = {"Zoot", "Jimmy", "Al", "Stan"}; cout<<setiosflags(ios_base::fixed); for(原创 2015-06-06 21:55:05 · 449 阅读 · 0 评论 -
输入输出--write
#include using namespace std;struct Date { int mondy, day, year;};int main() { Date dt = {7, 27, 93}; ofstream file("date.dat", ios_base::binary); file.write(reinterpret_cast(&dt), sizeof(d原创 2015-06-06 22:41:22 · 373 阅读 · 0 评论 -
输入输出--数值转换为字符串
#include #include #include using namespace std;templateinline string toString(const T &v) { ostringstream os; os<<v; return os.str();}int main() { string str1 = toString(5); cout<<str1<<原创 2015-06-06 22:51:19 · 511 阅读 · 0 评论 -
cout.get() P494
#include #include using namespace std;int main () { char ch; while ( ( ch = cin.get() ) != EOF) cout.put(ch); return 0;}原创 2015-06-06 23:17:42 · 509 阅读 · 0 评论