按引用传递的std ::字符串的数组 [英] Passing a array of std::string by reference

查看:122
本文介绍了按引用传递的std ::字符串的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I'ld喜欢创造传递不通过引用一个std :: string要修改的功能,

I'ld like to create a function that passes not a std::string by reference to be modified,

void changeStr(std::string &str)
{
    str = "Hello World!";
}

,而是一个完整的,固定大小的std ::字符串(函数会做同样的:一些属性特定字符串的每个空间阵列中)的阵列。但我不知道这是适当的语法...

, but rather an entire, fixed-sized array of std::strings (the function will do exactly the same: attribute some specific strings to each space in the array). But I don't know which is the appropriate syntax...

推荐答案

下面是如何!

//Change the 10 to whatever size you'd like
void changeStr(std::string (&str)[10]) {
}

这当然是一个静态的大小,其他的答案,但是,是的更好的方法完成你需要灵活的。

This of course, is for a static size, the other answers, however, are better methods accomplishing what you need with flexibility.

这篇关于按引用传递的std ::字符串的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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