标签:nim class r++ like alt pre 技术 bubuko i++
//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; }
标签:nim class r++ like alt pre 技术 bubuko i++
原文地址:https://www.cnblogs.com/perservence/p/9080134.html