aliyun的maven怎么配置不到eclipse
满意答案
虽然有一种方法可以使用模板并通过引用传递C数组,但我不确定这是否是您真正想要的: 示例
在C ++ 11中,我更喜欢使用
std::intializer_list
来使调用foo("c", {"a", "b", "c"})
按预期工作:#include <initializer_list> bool foo(const char* arg, std::initializer_list<const char*> strings) { for (const char* str : strings) { /* ... */ } }
虽然我们在这里,你应该考虑使用C ++的字符串工具而不是从C继承的字符串工具:
#include <initializer_list> #include <string> bool foo(const std::string& arg, std::initializer_list<std::string> strings) { for (const auto& str : strings) { if (arg == str) { return true; } } return false; }
请注意,
std::initializer_list
不拥有它提供访问的值,因此如果要存储它,请使用适当的容器,如std::vector
。另外,如果你想要检查
str
是否存在arg
,为什么不使用std::find
?#include <algorithm> #include <initializer_list> #include <string> bool foo(const std::string& arg, std::initializer_list<std::string> strings) { return std::find(strings.begin(), strings.end(), arg) != strings.end(); }
While there is a way to make that work using templates and passing C-arrays by reference, I'm not sure if that is what you really want: example
In C++11 I'd much prefer to use a
std::intializer_list
to make the callfoo("c", {"a", "b", "c"})
work as intended:#include <initializer_list> bool foo(const char* arg, std::initializer_list<const char*> strings) { for (const char* str : strings) { /* ... */ } }
While we're at it, you should consider using C++'s string facilities over those inherited from C:
#include <initializer_list> #include <string> bool foo(const std::string& arg, std::initializer_list<std::string> strings) { for (const auto& str : strings) { if (arg == str) { return true; } } return false; }
Note that a
std::initializer_list
does not own the values it provides access to, so if you want to store it, use a proper container likestd::vector
instead.Also, if checking for the presence of
arg
instr
is all you want to do, why not usestd::find
?#include <algorithm> #include <initializer_list> #include <string> bool foo(const std::string& arg, std::initializer_list<std::string> strings) { return std::find(strings.begin(), strings.end(), arg) != strings.end(); }
相关问答
更多c ++传递数组直接到函数(c++ pass array directy to function)
如何将数组从c ++库传递给c#(How to pass an array from a c++ library to c#)
将volatile数组传递给c ++中的函数(Passing volatile array to function in c++)
如何将3d数组传递给c ++中的函数?(How to pass and return 3d array to a function in c++?)
在C / C ++中将指针(数组的名称)传递给函数(passing pointers (the name of array) into function in C/C++)
如何从数组传递到vector - c ++(How to pass from array to vector - c++)
C#数组传递函数如C ++?(C# array pass in function like C++?)
Objective - C - >传递数组作为函数参数(Objective - C -> Pass Array As Function Argument)
C ++将不同大小的不同数组传递给相同的函数(C++ Pass different arrays of different sizes to same function)
c ++将char数组传递给函数并进行更改(c++ pass char array to function and change it)
相关文章
更多maven 下载加速 aliyun 国内镜像配置
aliyun maven仓库地址-国内快速访问maven私有库
maven jetty:run “找不到符号”
使用eclipse创建maven项目图文详解
Eclipse Hadoop环境配置
Eclipse下配置使用Hadoop插件
Eclipse下配置Hadoop环境
Hadoop Eclipse 配置
在Eclipse中配置Hadoop插件
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!