将字符串移动到矢量 [英] Move string into vector

查看:307
本文介绍了将字符串移动到矢量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法将 std :: string中的内容移动到std :: vector中?我认为现在有了语法参考,这个操作有时会非常有用。

Is there a way to move the content from a std::string into a std::vector? I think with now having rvalue-references in the language this operation would be very useful sometimes.

推荐答案

可以从一种对象类型移动到另一种对象类型。但是,这些对象类型必须设计为允许这样。 向量 string 不是。

一个对象允许它是 std :: vector 有一个构造函数,它接受 std :: string&& 。它没有这样的构造函数。此外,向量必须是 string 的朋友才能获得其内部。

A good clue that an object allows it would be if std::vector has a constructor that takes a std::string&&. It has no such constructor. Also, vector would have to be a friend of string to get at its internals.

这篇关于将字符串移动到矢量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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