大家可以下载后用Vim 或者 Sublime Text等文本编辑器查看

Conference: http://blog.csdn.net/candy1232009/article/details/7032526

//ofstream fout;	//C style
//fout.open("fout.txt"); ofstream fout ("fout.txt"); //C++ out stream recommend
ifstream fin ("fio.cpp"); //fout.close() //Not necessary in C++, because C++ do it automatically //Copy the whole file int main(){
ofstream fout ("SourceCodeCopy.cpp");
ifstream fin ("SourceCode.cpp");
string str;
while(getline(fin, str)){ //Discards newline char
fout << str << endl; //... must add it back
}
return 0;
} //calculate the average number int main(){
int i, num, cur;
cin >> num; //double* array = (double*) malloc(num * sizeof(double)); //C style
double* array = new double[num]; //C++ style
double ave = 0.0;
for(i = 0; i < num; ++i){
cin >> array[i];
ave += array[i];
}
cout << "Ave is the " << ave / num << endl;
//free(array); //C style
delete[] array; //[] means delete all the Array, if "delete array" means delete only the array[0] return 0;
} //one double number array Example int main(){
double* pd = new double; cin >> *pd;
cout << *pd;
delete pd; return 0;
} //Introduce Vector int main(){
vector <double> vc; //init a vector
vc.push_back(27.8); //insert element to its tail
vc.push_back(54.2); //vc[2] = 89.3 //Don't do in this way, no such spacez for(i = 0; i < vc.size(); ++i){
cout << vc[i] << endl;
}
return 0;
} //Answer is 0 0 89.3 27.8 54.2 (5 elements) int main(){
int i;
vector <double> vc(3); //init a space long for 3
vc.push_back(27.8);
vc.push_back(54.2); vc[2] = 89.3;// for(i = 0; i < vc.size(); ++i){
cout << vc[i] << endl;
} return 0;
} //Copy an entire file into a vector of string int main(){
vector <string> v;
ofstream out ("SourceCodeCopy.cpp");
ifstream in ("SourceCode.cpp");
string line;
while(getline(in, line)){
v.push_back(line);
}
for(int i = 0; i < v.size(); ++i){
out << 1 + i << ": " << v[i] << endl;
} return 0;
} //Class work
//give a number N, and make n random numbers into a file int main(){
srand((int)time(NULL));
int i, n;
vector <int> v;
ofstream out ("rand_num.txt"); cin >> n;
while(n--){
v.push_back(rand() % 65536);
}
for(i = 0; i < v.size(); ++i){
out << v[i] << endl;
} return 0;
} //make n numbers in the range [0, 1) #include <iostream>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm> using namespace std; int main(){
srand((int)time(NULL));
int i, n;
vector <double> v;
ofstream out ("rand_num.txt"); cin >> n;
while(n--){
v.push_back((double)rand() / (double)RAND_MAX);
}
for(i = 0; i < v.size(); ++i){
out << v[i] << endl;
} return 0;
}

  

面向对象程序设计-C++ Steam & Vector 【第三次上课笔记】的更多相关文章

  1. {key}面向对象程序设计-C++ polymorphism 【第十三次上课笔记】

    Peronal Link: http://segmentfault.com/a/1190000002464822 这节课讲了本门课程 面向对象程序设计中最为重要的一个部分 - 多态 /******** ...

  2. [.net 面向对象程序设计进阶] (11) 序列化(Serialization)(三) 通过接口 IXmlSerializable 实现XML序列化 及 通用XML类

    [.net 面向对象程序设计进阶] (11) 序列化(Serialization)(三) 通过接口 IXmlSerializable 实现XML序列化 及 通用XML类 本节导读:本节主要介绍通过序列 ...

  3. [.net 面向对象程序设计进阶] (7) Lamda表达式(三) 表达式树高级应用

    [.net 面向对象程序设计进阶] (7) Lamda表达式(三) 表达式树高级应用 本节导读:讨论了表达式树的定义和解析之后,我们知道了表达式树就是并非可执行代码,而是将表达式对象化后的数据结构.是 ...

  4. 对于“2017面向对象程序设计(Java)第三周学习总结”存在问题的反馈

    对于“2017面向对象程序设计(Java)第三周学习总结”存在问题的反馈 一:教学中存在的学习问题 “1.由于同学们平时练习不足,上课总是出现跟不上老师的节奏的现象. 2.个别同学上课不认真听讲,打开 ...

  5. «面向对象程序设计(java)»第三周学习总结 周强 201771010141

    实验目的与要求 (1)进一步掌握Eclipse集成开发环境下java程序开发基本步骤: (2)熟悉PTA平台线上测试环境: (3)掌握Java语言构造基本程序语法知识(ch1-ch3): (4)利用已 ...

  6. c++面向对象程序设计 谭浩强 第三章答案

    2: #include <iostream> using namespace std; class Date {public: Date(int,int,int); Date(int,in ...

  7. [.net 面向对象程序设计进阶] (18) 多线程(Multithreading)(三) 利用多线程提高程序性能(下)

    [.net 面向对象程序设计进阶] (18) 多线程(Multithreading)(二) 利用多线程提高程序性能(下) 本节导读: 上节说了线程同步中使用线程锁和线程通知的方式来处理资源共享问题,这 ...

  8. 2017面向对象程序设计(Java)第三周学习总结

    白驹过隙,日月如梭,一转眼,我们已经度过了第三周的学习时光,随着时间的一天天流逝,我么对知识的积累也逐渐增多.当然,我们还有许许多多需要改进的地方.下面,我将对第三周的助教工作进行总结,望老师及同学们 ...

  9. 达拉草201771010105《面向对象程序设计(java)》第三周学习总结

    达拉草201771010105«面向对象程序设计(java)»第三周学习总结 第一部分:实验部分  1.实验目的与要求 (1)进一步掌握Eclipse集成开发环境下java程序开发基本步骤: (2)熟 ...

随机推荐

  1. appium获取app应用的package和 activity。---新手总结(大牛勿喷,新手互相交流)

    从网上搜索的方法: 如下: 1.查看源码 2.日志法a.启动待测apkb.开启日志输出:adb logcat>D:/log.txtc.关闭日志输出:ctrl+cd.查看日志直接搜索 :Displ ...

  2. 03-C语言编码规范和变量

    目录: 一.C语言的编码规范 二.变量 三.浮点型float 四.变量名命名规则 五.变量作用域与生命周期 回到顶部 一.C语言的编程规范 1 语句可以分开放在任意位置 2 空格可以让代码更清晰 3 ...

  3. c风格字符串函数

    十一.C 风格字符串  1)字符串操作  strcpy(p, p1) 复制字符串  strncpy(p, p1, n) 复制指定长度字符串  strcat(p, p1) 附加字符串  strncat( ...

  4. Delphi中取整函数Round的Bug解决

    Delphi中 Round函数有个Bug一旦参数是形如 XXX.5这样的数时如果 XXX 是奇数 那么就会 Round up如果 XXX 是偶数 那么就会 Round down例如 Round(17. ...

  5. 如何提取出ppt中的文字?

    最近在看一位老师的教学视频,视频里大部分的知识都记录在ppt里,于是很想将ppt中的文字提取出来,如果我一页一页地粘贴复制的话,效率低到吓人,因为一章的ppt有130多页,于是在网上搜索了一下方法,与 ...

  6. Swift与Objective-C API的交互

    互用性是让 Swift 和 Objective-C 相接合的一种特性,使你能够在一种语言编写的文件中使用另一种语言.当你准备开始把 Swift 融入到你的开发流程中时,你应该懂得如何利用互用性来重新定 ...

  7. 浅谈CSS布局

    在No.4中谈及了下盒子模型,引出布局模型 1.布局模型有三类: 1)流动模型  flow(默认) 2)浮动模型  float 3)层模型  layer 2.文档流 :指的是文本沿着从左到右的方向展开 ...

  8. hadoop的集群安装

    hadoop的集群安装 1.安装JDK,解压jar,配置环境变量 1.1.解压jar tar -zxvf jdk-7u79-linux-x64.tar.gz -C /opt/install //将jd ...

  9. Name lookup

    Name lookup Types of lookup Argument-dependent lookup Template argument deduction overload resolutio ...

  10. BZOJ 1652: [Usaco2006 Feb]Treats for the Cows( dp )

    dp( L , R ) = max( dp( L + 1 , R ) + V_L * ( n - R + L ) , dp( L , R - 1 ) + V_R * ( n - R + L ) ) 边 ...