aliyun的maven怎么配置不到eclipse

2022-04-29 17:04

满意答案

虽然有一种方法可以使用模板并通过引用传递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 call foo("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 like std::vector instead.

Also, if checking for the presence of arg in str is all you want to do, why not use 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();
}

相关问答

更多

c ++传递数组直接到函数(c++ pass array directy to function)

虽然有一种方法可以使用模板并通过引用传递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#(How to pass an array from a c++ library to c#)

您可以在C#代码中声明该方法作为返回IntPtr ,然后将其转换为您需要的数组(您在C ++代码中拥有的对象的托管版本数组)。 You can declare the method in your C# code as returning IntPtr and then convert it to the array you need (an array of the managed version of the objects you have in your C++ code) .

将volatile数组传递给c ++中的函数(Passing volatile array to function in c++)

只需将volatile添加到您的参数: void processArray(volatile const uint8_t** inputArray) 另外,当您使用const作为参数时,您还需要传递一个const指针,这意味着您可能需要以下内容: processArray((volatile const uint8_t**)array); Just add volatile to your parameter: void processArray(volatile const uint8_t...

如何将3d数组传递给c ++中的函数?(How to pass and return 3d array to a function in c++?)

我不知道我是否完全理解你的问题。 但是你绝对可以将指针本地存储在对象中并在其他地方引用它。 像这样的东西: class M { public: M(int(*tbl)[8][3]) : table(tbl) { } int(*table)[8][3]; int i, j, k; public: void pass(int size); }; void M::pass(int s) { for (i = 0; i<s; i++) { ...

在C / C ++中将指针(数组的名称)传递给函数(passing pointers (the name of array) into function in C/C++)

a是一个数组,而不是指针。 他们不是一回事。 但是,名称a可以隐式转换为指针(值为&a[0] )。 例如; int main() { int a[] = {1,2,3,4}; int *p = a; // p now has the value &a[0] 现在,在这个部分代码片段之后,假设i是一个整数值,语言的规则相当于; a[i]相当于*(a + i) ,相当于*(&a[0] + i) p[i]相当于*(p + i) 现在,由于...

如何从数组传递到vector - c ++(How to pass from array to vector - c++)

我看了上面链接的代码,发现了很多可以使用STL向量而不是定义的数组的地方。 例如,下面是如何用向量替换几个数组,然后初始化它们的值的示例: #include <iostream> #include <limits> #include <vector> // Number of vertices in the graph static const int V = 5; int main() { // Rather than use: // int key[V]; // b...

C#数组传递函数如C ++?(C# array pass in function like C++?)

当然。 但是,您无法修改指针,因此您需要单独传递偏移量。 此外,您不需要传递长度,因为所有C#Arrays都有.Length属性来获取数组大小。 void MyFunction(int[] A, int offset) { MyFunction2(A, offset + 1); } Sure. However you can't modify pointers, so you would need to pass the offset separately. Also, you don'...

Objective - C - >传递数组作为函数参数(Objective - C -> Pass Array As Function Argument)

当然是。 C-数组: - (void)myFunction:(int*)array; ... int bar[12]; [obj myFunction:bar]; NSArray的: - (void)myFunctionWithNSArray:(NSArray*)array; ... NSArray *array = [[NSArray alloc] initWithObjects...]; [obj myFunctionWithNSArray:array]; Yes, of course...

C ++将不同大小的不同数组传递给相同的函数(C++ Pass different arrays of different sizes to same function)

一种可能性是一个template函数: template <typename T, std::size_t Dim1, std::size_t Dim2> void f(T(&)[Dim1][Dim2]) { std::cout << Dim1 << ", " << Dim2 << "\n"; } 请参阅http://ideone.com/b60h1e上的演示。 注意这将实例化函数模板的三个不同实例(每个不同尺寸组合的实例化)。 建议改为使用std::vector<std::vector...

c ++将char数组传递给函数并进行更改(c++ pass char array to function and change it)

将参数传递给函数时,它通常按值传递,这意味着它的值被复制。 如果你想改变它,你必须通过引用传递它。 对于指针也是如此,如果你想更改指针,那么你也需要通过引用传递它: void change_array(const char*& target) { ... } When you pass an argument to a function, it's normally passed by value, meaning its value is copied. If you want to chan...

相关文章

更多

maven 下载加速 aliyun 国内镜像配置

maven如果连接maven 国外中心仓库下载,速度有可能很慢,配置aliyun的maven仓库是个不 ...

aliyun maven仓库地址-国内快速访问maven私有库

oschina的maven私有库访问不了,可以使用阿里云的maven私有仓库 修改你的maven配置文 ...

maven jetty:run “找不到符号”

maven jetty:run “找不到符号”

使用eclipse创建maven项目图文详解

打开ecilpse,File--->New--->Other--->Maven--->Maven Pr ...

Eclipse Hadoop环境配置

群配置基本信息 Ubuntu 10.04 Hadoop 0.20.2 1 个 namenode 162 ...

Eclipse下配置使用Hadoop插件

前提,请先配置好Hadoop集群,并启动Hadoop守护进程。 集群搭建参见:http://www.l ...

Eclipse下配置Hadoop环境

Hadoop集群搭建完成后,每次开发完map/reduce程序后,需要用打包,上传数据等步骤,然后命令 ...

Hadoop Eclipse 配置

重装系统后有折腾了好久,才搞定。。感觉还是不靠谱。。先记录下 Hadoop 伪分布式配置: 1,had ...

在Eclipse中配置Hadoop插件

1.安装插件 准备程序: eclipse-3.3.2 (这个版本的插件只能用这个版 ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本