C++ //练习 9.14 编写程序,将一个list中的char*指针(指向C风格字符串)元素赋值给一个vector中的string。

C++ Primer(第5版) 练习 9.14

练习 9.14 编写程序,将一个list中的char*指针(指向C风格字符串)元素赋值给一个vector中的string。

环境:Linux Ubuntu(云服务器)
工具:vim
代码块
cpp 复制代码
/*************************************************************************
	> File Name: ex9.14.cpp
	> Author: 
	> Mail: 
	> Created Time: Mon 26 Feb 2024 01:33:44 PM CST
 ************************************************************************/

#include<iostream>
#include<vector>
#include<list>
using namespace std;

int main(){
    vector<string> str;
    list<const char*> li = {"hello", "world", "help"};

    str.assign(li.begin(), li.end());

    for(const auto s : str){
        cout<<s<<" ";
    }
    cout<<endl;

    return 0;
}
运行结果显示如下
相关推荐
wljy11 天前
二、进制状态转换
linux·运维·服务器·c语言·c++
云泽8081 天前
笔试算法 -位运算篇(二):从唯一字符到消失数字
c++·算法·位运算
ʚ希希ɞ ྀ1 天前
不同路径|| -- dp
算法
繁华落尽,倾城殇?1 天前
[C++11] : atomic,nullptr,default/delete,enum class
开发语言·c++·c++11·nullptr·atomic·enum class·default/delete
01_ice1 天前
C语言数据在内存中的存储
c语言·开发语言
代码村新手1 天前
C++-二叉搜索树
开发语言·c++
bucenggaibian1 天前
《C语言》编程前置:计算机底层逻辑(诞生的基础)
c语言·程序框架·编译运行·内存地址·底层逻辑
IT 行者1 天前
SimHash 与 MinHash:相似性计算的双子星算法
算法·hash·比对
智者知已应修善业1 天前
【51单片机8位数码管动态显示日期小数点风格】2023-11-13
c++·经验分享·笔记·算法·51单片机