将字符串从char *复制到std :: string的优雅方式 [英] Elegant way to copy substring from char* to std::string

查看:1053
本文介绍了将字符串从char *复制到std :: string的优雅方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个 char *

char* line = "This is a great day";
string subLine;

我想要 subLine code>是一个很棒的

I want that subLine will include: is a great

(从第5个地方复制,后面10个字符)。

(copy from place 5, the next 10 characters).

有没有办法,而不是将 char * 转换为 std :: string

Is there a way to do that instead of converting the char* to std::string?

推荐答案

您可以使用此页面,如下所示:

You can use the fifth constructor from this page, as follows:

char* line = "This is a great day";
string subLine(&line[5], 10);

这篇关于将字符串从char *复制到std :: string的优雅方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆