小编Sim*_*ver的帖子

如何创建用户定义大小但没有预定义值的向量?

在C++中,可以创建一个预定义大小的数组,例如20 int myarray[20].但是,关于向量的在线文档并未显示初始化向量的相似方法:相反,应使用例如初始化向量std::vector<int> myvector (4, 100);.这给出了大小为4的向量,其中所有元素都是值100.

如何使用预定义的大小初始化向量而没有预定义的值,就像使用数组一样?

c++ vector

48
推荐指数
1
解决办法
11万
查看次数

将方法存储在变量中时出错

Class c = v.getClass();
try {
    Method m = c.getMethod("something");
    if(!m.getReturnType().equals(Boolean.TYPE)) {return false;}
} catch(NoSuchMethodException e) {return false;}
Run Code Online (Sandbox Code Playgroud)

...... v某个类的对象在哪里.
当我尝试编译时,我得到:

错误:找不到符号
方法m = c.getMethod("something");
^

方法是一种驻留的类型java.lang.reflect.Method.据我所知java.lang,默认导入后续内容,但我甚至明确地这样做了:

import java.lang.*;
Run Code Online (Sandbox Code Playgroud)

所以我的问题是:如何使我的编译器识别该类Method,或者如何存储其他的returnvalue getMethod

PS:请忽略对getMethod的未经检查的调用,这将是一个不同时间的问题(可能是一个不同的问题).

java

5
推荐指数
1
解决办法
64
查看次数

G ++似乎没有认识到-std = c ++ 11

我用-std=c++11给定的标志编译我的代码,我得到各种错误描述我应该使用相同的标志.此外,auto不承认是一种类型.

Makefile文件:

GCCPATH = /path/gcc/5.3.0
CC = $(GCCPATH)/bin/g++
DARGS = -ggdb               #debug arguments
CARGS = -std=c++11          #C arguments
WARGS = -Wall -Wextra       #warning arguments
AARGS = $(DARGS) $(CARGS) $(WARGS)  #all arguments
GCCLIBPATH = $(GCCPATH)/lib64
LIBS = -l curl
LIBD = -L $(GCCLIBPATH) -Wl,-rpath=$(GCCLIBPATH)

.PHONY: webspider

webspider: ../title/htmlstreamparser.o filesystem.o
    $(CC) $(AARGS) -o $@ $@.cpp $+ $(LIBS) $(LIBD)

filesystem:
    $(CC) $(AARGS) -c $@.cpp
Run Code Online (Sandbox Code Playgroud)

我得到的警告和错误:

warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
warning: range-based ‘for’ …
Run Code Online (Sandbox Code Playgroud)

c++ makefile c++11

1
推荐指数
1
解决办法
882
查看次数

如何查看迭代器的索引?

所以我有一个字符串source,我用迭代器循环:

iterator = iter(source)
for char in iterator:
  do stuff
Run Code Online (Sandbox Code Playgroud)

但是,现在说我有一个签入do stuff,我将迭代器的值与'h'进行比较.然后我想以某种方式看看'h'是否后跟"ello",然后将前十个字符添加到列表中.
为此,我自己的想法是找出哪个索引与迭代器的当前位置相对应,以便我可以说:

indIt = index(char)
if source[indIt + 1: indIt + 6] == "ello ":
  someList.append(source[indIt + 7:indIt + 16])
  indIt += 17
  char = indIt #which may also be fun to know how it can be done, if
Run Code Online (Sandbox Code Playgroud)

这意味着对于给定的输入hello Sandra, oh and hello Oscar, i welcome you both!,someList将包含["Sandra,oh","Oscar,i w"].

那么,我可以通过某种方式确定迭代器当前位置对应的索引吗?

python iterator

0
推荐指数
1
解决办法
65
查看次数

标签 统计

c++ ×2

c++11 ×1

iterator ×1

java ×1

makefile ×1

python ×1

vector ×1