大家可以下载后用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. PowerShell Remove all user defined variable in PowerShell

    When PS scripts executes, it is possibly create much user defined variables. So, sometimes these var ...

  2. struts2上传下载

    struts上传下载必须引入两个jar文件: commons-fileupload-x.x.x.jar和comons-io-x.x.x.jar上传文件 import java.io.BufferedI ...

  3. 关于地址的理解 C++

    #include <iostream> using namespace std; int main(){ ; int* ptr; ptr=&a; cout<<& ...

  4. cnzz广告管家使用心得

    步着谷歌广告管家的后尘,国内百度公司和知名网络流量数据统计公司cnzz也分别推出了百度广告管家和cnzz广告管家.笔者分别注册了这两个网站.通过一段时间的使用,写下此文,希望对各位站长朋友们有所帮助. ...

  5. CMake 教程

    CMake是一个跨平台的程序构建工具,比如起自己编写Makefile方便很多. 介绍:http://baike.baidu.com/view/1126160.htm 本文件不介绍CMake的基本语法, ...

  6. poj 2503 Babelfish(Map、Hash、字典树)

    题目链接:http://poj.org/bbs?problem_id=2503 思路分析: 题目数据数据量为10^5, 为查找问题,使用Hash或Map等查找树可以解决,也可以使用字典树查找. 代码( ...

  7. Python生成随机数的方法

    这篇文章主要介绍了Python生成随机数的方法,有需要的朋友可以参考一下 如果你对在Python生成随机数与random模块中最常用的几个函数的关系与不懂之处,下面的文章就是对Python生成随机数与 ...

  8. c#关于EXCEL导入数据库的做法

    以下例子转载:互联网 先在类中定义一个方法名为ExecleDs的方法,用于将Excel表里的数据填充到DataSet中,代码如下 public DataSet ExecleDs(string file ...

  9. input autocomplete 下拉提示+支持中文

    js 代码: $.getJSON("/Foreign/Getforeign_routeEndPoint", function (data) {            $(" ...

  10. Enze Third day(c#中选择结构【if...else】)

    哈喽,又到了我总结课堂知识的时间了.今天在云和学院学的是C#中的“选择结构”下的If语句.下面就来总结一下今天所学的吧. 理论:If语句是最常用的选择结构语句.它主要根据所给定的条件(常由关系表达式和 ...