现在的位置: 首页 > 综合 > 正文

C++ Primer 中文版 第4版 习题9.28

2012年11月12日 ⁄ 综合 ⁄ 共 829字 ⁄ 字号 评论关闭

/*我在这里写下部分C++ Primer 中文版 第4版 习题的个人解答和看法(注:我没有买答案书,所以不保证正确,你觉得错的,希望你能告诉我)源代码运行的要求和书上一样,省略了预编译和using行。假如有什么说的不详细,你还不懂,可以问我,不过我也是初学者,不一定知道阿,看我还在学C++ Prime 就知道我是初学者了。欢迎转载,但是请保留作者名“九天雁翎”。*/

 

int main()
{
 list<char *> pcList;
 char *word1="I";
 char *word2="am";
 char *word3="a";
 char *word4="good";
 char *word5="boy";
 pcList.push_back(word1);
 pcList.push_back(word2);
 pcList.push_back(word3);
 pcList.push_back(word4);
 pcList.push_back(word5);
 list<char *>::const_iterator pcLFirst = pcList.begin(),pcLLast = pcList.end();
 cout <<"the pcList:"<<endl;
 for(;pcLFirst != pcLLast;++pcLFirst)
 {
  cout << *pcLFirst<<" ";
 }
 cout<<endl;
 pcLFirst =pcList.begin();
 vector<string> svec;
 svec.assign(pcLFirst,pcLLast);
 cout <<"the svec:"<<endl;
 for(vector<string>::const_iterator first = svec.begin(),last = svec.end();
  first != last;++first)
 {
  cout << *first<<" ";
 }
 cout<<endl;
 return 0;
}

 

抱歉!评论已关闭.