
C++课程笔记
juddi
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
C++中setiosflags( ) 的用法
setiosflags( ios::fixed ),头文件为:include<iomanip>.在遇到要计算浮点数且希望能控制其输出、精度、小数点后的位数等时,用setiosflags( ios::fixed )来控制。 1. setprecision( )使用setprecision(n)可控制输出流显示浮点数的数字个数。C++默认的流输出数值有效位是6。setpre...转载 2018-09-18 17:50:35 · 36215 阅读 · 5 评论 -
C++中的cin、cin.get()、cin.getline()、getline()、gets()等函数的用法
1、cin2、cin.get()3、cin.getline()4、getline()5、gets()6、getchar()1.cin>>用法1:最基本,也是最常用的用法,输入一个数字:#include <iostream>using namespace std;main (){int a,b;cin>>a>...转载 2018-10-19 11:24:40 · 654 阅读 · 0 评论 -
设计包含静态数据成员的Student类
设计包含静态数据成员的Student类,在该类定义中包括:数据成员:学号,年龄,分数score,及静态数据成员学生人数count;定义成员函数用于设置和读取及显示学号,年龄,分数,累计学生人数;静态成员函数getCount( ) 用于返回总人数;外部函数average()用于求平均值。在main函数中,输入某班同学的成绩,并调用上述函数求全班学生的平均分。 #include &...原创 2018-10-19 11:27:31 · 5613 阅读 · 1 评论 -
C++中的tab(\t)
#include <iostream>using namespace std; int main() { int i; for(i=0;i<80;i++) if(i%10==0)cout<<i/10; else cout<<' ';for(i=0;i<80;i++) cout<<i%...原创 2018-10-19 10:11:19 · 10371 阅读 · 0 评论 -
C++中的退格(\b)
#include <iostream> using namespace std; int main() { cout << "abcde\b"<<"123"<<endl; cout << "abcde\b\b\b"<<&q原创 2018-10-19 10:09:57 · 10098 阅读 · 5 评论 -
C++中的回车(\n)和换行(\r)
‘\n’ 换行,光标移到下一行的开头;'\r' 回车,光标移到当前行的开头,不会换到下一行,如果接着输出的话,本行以前的内容会被逐一覆盖;#include <iostream> using namespace std; int main() { cout << "this is the first line\n"; c...原创 2018-10-19 10:07:48 · 32238 阅读 · 1 评论 -
c++ 读入一个字符
#include <iostream>using namespace std;int main(){ char c; cin>>c; //自动过滤掉不可见字符(如空格 回车 tab等),这些字符被当作间隔符号,输入不可见字符不识别 cout <<c<<" "<< c %2<< endl;原创 2018-10-15 11:31:55 · 11424 阅读 · 0 评论 -
C++中类的数据成员是字符串
可以用分别使用:字符数组,string类的对象,字符指针表示字符串。实现方法略有不同。#include <iostream>#include <string>using namespace std;class CStudent{private: int number; char name[20]; st...转载 2018-09-18 17:49:07 · 3956 阅读 · 0 评论 -
C++中一般引用作形参和常引用作形参的问题
#include<iostream>using namespace std;int f(const int &a){return a;}int g(int &a){return a;}int h(int a){return a;}int main(){ int x=3; cout<<f(x)<<endl;...转载 2018-09-18 17:50:07 · 5868 阅读 · 0 评论 -
C++中继承与组合的区别
对象和类是C++中的重要内容,对象(Object)是类(Class)的一个实例(Instance)。面向对象设计的重点是类的设计,而不是对象的设计。对于C++程序而言,设计孤立的类是比较容易的,难的是正确设计基类及其派生类。这就和“继承”(Inheritance)和“组合”(Composition)有重要联系了。类的组合和继承都是软件重用的重要方式。但二者的概念和用法不同。继承描述的是类与类之...转载 2018-09-18 17:50:23 · 766 阅读 · 0 评论 -
老师把我的源程序改了哪些地方?
修改前后的源代码分别保存成2个word文档,如before.docx和after.docx,然后用word自动比较。比较方法见下:如何比较两个word文档的差异_百度经验 https://jingyan.baidu.com/article/215817f7ced9801eda1423d9.html...转载 2018-10-20 11:24:34 · 381 阅读 · 0 评论