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

本文提供了C++ Primer第四版中部分习题的解答示例,通过使用C++标准库中的list和vector,演示了如何操作字符指针列表,并将其转换为字符串向量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/*我在这里写下部分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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值