大家可以下载后用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. bzoj 1046 : [HAOI2007]上升序列 dp

    题目链接 1046: [HAOI2007]上升序列 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3620  Solved: 1236[Submit] ...

  2. pcap文件格式解析

    pcap文件格式是常用的数据报存储格式,包括wireshark在内的主流抓包软件都可以生成这种格式的数据包 下面对这种格式的文件简单分析一下:    pcap文件的格式为:  文件头    24字节  ...

  3. [转] iOS多线程编程之Grand Central Dispatch(GCD)介绍和使用

    介绍: Grand Central Dispatch 简称(GCD)是苹果公司开发的技术,以优化的应用程序支持多核心处理器和其他的对称多处理系统的系统.这建立在任务并行执行的线程池模式的基础上的.它首 ...

  4. KVO 的使用和举例

    KVO(key-value Observer),通过命名可以联想到,一个监视着监视着键值配对,让一个对象A来监视另一个对象B中的键值,一旦B中的受监视键所对应的值发生了变化,对象A会进入一个回调函数, ...

  5. python使用easygui写图形界面程序

    我 们首先下载一个类库easygui,它是一个Python用于简单开发图形化界面的类库,打开easygui的下载网页 http://sourceforge.net/projects/easygui/? ...

  6. ddraw 视频下画图 不闪烁的方法

    我们如果是在在RGB视频上画图(直线,矩形等),一般采用双缓冲区继续,使用内存MemoryDC,来实现画的图形在视频上显示不闪烁的功能,但是我们知道用RGB显示视频都是使用GDI进行渲染,这样很耗CP ...

  7. hdoj 5311 Hidden String(KMP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5311 思路分析:该问题要求在字符串中是否存在三个不相交的子串s[l1..r1], s[l2..r2], ...

  8. android service和activity的通讯

    我们须要用下面方式来启动service: </pre><pre name="code" class="java"><span st ...

  9. Windows最常用的几个网络CMD命令总结

    Windows最常用的几个网络CMD命令总结 http://www.cnblogs.com/sbaicl/archive/2013/03/05/2944001.html 一.ping 主要是测试本机T ...

  10. Android 开发笔记 “调用WebService”

    WebService是一种基于SOAP协议的远程调用标准,通过webservice可以将不同操作系统平台.不同语言.不同技术整合到一块.在Android SDK中并没有提供调用WebService的库 ...