小编use*_*688的帖子

将字符长度从数组复制到std :: string

我试图将5个字符从字符数组复制到 std::string

char name[] = "Sally Magee";
std::string first;
copy(name, name + 5, first.begin()); //from #include <algorithm>
std::cout << first.c_str();
Run Code Online (Sandbox Code Playgroud)

但是我得到了字符串加上一大堆我不想要的不可打印的字符.有任何想法吗?谢谢.

c++ arrays string copy strncpy

3
推荐指数
1
解决办法
3696
查看次数

标签 统计

arrays ×1

c++ ×1

copy ×1

string ×1

strncpy ×1