实验5
Posted perservence
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了实验5相关的知识,希望对你有一定的参考价值。
//6-17 改: #include <iostream> using namespace std; int main(){ int a,*p=&a; *p=9; cout<<"The value at p: "<<*p; return 0; }
//6-18 #include <iostream> using namespace std; int fn1(){ int *p=new int (5); return *p; delete p; } int main(){ int a=fn1(); cout<<"the value of a is: "<<a; return 0; } //delete 用来删除由new建立的对象
//ex3.cpp #include <iostream> #include <vector> #include <string> using namespace std; // 函数声明 void output1(vector<string> &); void output2(vector<string> &); int main() { vector<string>likes, dislikes; // 创建vector<string>对象likes和dislikes likes.push_back( "favorite book" ); likes.push_back(" music"); likes.push_back("film"); likes.push_back("paintings"); likes.push_back("anime"); likes.push_back("sport"); likes.push_back("sportsman"); likes.push_back("etc"); cout << "-----I like these-----" << endl; output1(likes); dislikes.push_back("running"); dislikes.push_back("studying"); dislikes.push_back("etc"); cout << "-----I dislike these-----" << endl; output1(dislikes); swap(likes, dislikes); cout << "-----I likes these-----" << endl; output2(likes); cout << "-----I dislikes these-----" << endl; output2(dislikes); return 0; } // 函数实现 // 以下标方式输出vector<string>数组对象v的元素值 void output1(vector<string> &v) { for (int i = 0; i<v.size(); i++) cout << v[i] << endl; } // 函数实现 // 以迭代器方式输出vector<string>数组对象v的元素值 void output2(vector<string> &v) { vector<string>::iterator itr = v.begin(); for (itr; itr != v.end(); itr++) cout << *itr << endl; }
以上是关于实验5的主要内容,如果未能解决你的问题,请参考以下文章
[NTUSTISC pwn LAB 7]Return to libc实验(puts泄露libc中gadget片段定位)