/*我在这里写下部分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;
}
本文提供了C++ Primer第四版中部分习题的解答示例,通过使用C++标准库中的list和vector,演示了如何操作字符指针列表,并将其转换为字符串向量。
1508

被折叠的 条评论
为什么被折叠?



