小编Man*_*dis的帖子

C++将结构的空向量传递给函数

我试图将一个空的结构向量传递给一个函数,该函数将从一个文件中读取,它将返回读取的记录数 - 它将是一个整数.

我在main中初始化结构向量,当我尝试将它传递给函数时,我会定期执行它:

int read_records(vector<player> player_info)
Run Code Online (Sandbox Code Playgroud)

它给了我一个"玩家未定义"的错误.我已经找到了一种绕过它的方法,你将在下面的代码中看到,但是逻辑让我相信应该有一种方法来传递空向量而不必填写第一个下标.

代码如下.请注意,读取功能尚未完成,因为我仍然想知道结构的向量.

#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <fstream>
using namespace std;

//function prototypes
int read_records(struct player* player_info);

/*
* Define a struct called player that will consist
* of the variables that are needed to read in each
* record for the players. 2 strings for the first
* and last names and 1 integer to hold the statistics
*/
struct player
{
    string first;
    string last;
    int stats; …
Run Code Online (Sandbox Code Playgroud)

c++ vector

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

如何在事务类上自动装配?

班级档案:

@Transactional(propagation=Propagation.REQUIRES_NEW)
public class ServiceImpl implements Service {
...
}
Run Code Online (Sandbox Code Playgroud)

Xml文件:

...
<bean id="service" class="com.sky.core.engine.impl.ServiceImpl">
...
Run Code Online (Sandbox Code Playgroud)

测试文件:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("testConfig.xml")
public class ServiceImplTest {

    private static final Logger log = Logger
            .getLogger(ServiceImplTest.class);

    @Autowired
    private ServiceImpl service;

    @Test
    public void test(){
       ...
    }
Run Code Online (Sandbox Code Playgroud)

例外:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.sky.core.engine.comp.impl.ServiceImplTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.sky.core.engine.impl.ServiceImpl com.sky.core.engine.impl.Service; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.sky.core.engine.comp.impl.ServiceImpl] found for dependency: expected at …
Run Code Online (Sandbox Code Playgroud)

java spring hibernate autowired

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

我有一个字符串,并希望在java中重复'l'次

从一个循环,我将得到的价值l.想象这个值是3.因此我想要一个字符串重复3次.这意味着我想要执行字符串*l,但这是不可能的,因为一个是字符串,一个是int.我确实需要字符串重复l次数.

例如,如果输入的字符串是"cat"并且l结果为3,我将得到输出"catcatcat".谢谢

这是我的编码:

import java.util.Scanner;

public class Task2 { 
    public static void main (String[] args){
        Scanner kb=new Scanner(System.in); 


        System.out.println("Please give me a message:"); 

        String strMessage = ("^[?=.*!@#$%^&*]+$");
        strMessage=kb.nextLine();



        System.out.println("Thank you! Now please give me a keyword:"); 

        String strKeyword=kb.nextLine();    

        String strAlphabet= "abcdefghijklmnopqrstuvwxyz";

        double Intlength2 = strKeyword.length();
        double Intlength = strMessage.length(); 
        double Intlength3 = Intlength/Intlength2;
        Intlength3 = Intlength/Intlength2;

        for (int l=0; l<Intlength3; l++){ 
Run Code Online (Sandbox Code Playgroud)

java string integer

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

即使未选中复选框,JCheckbox isSelected()也会返回true

JCheckbox虽然我以前经常使用它们,但我遇到了问题.

基本上,我创建一个带有复选框的非常简单的窗口,然后检查它们是否被选中.执行该检查时,JCheckbox即使不是,也会显示为已选中.这是我的代码.要重现我的问题,请运行该项目,然后单击"开始".即使createStatisticsFilesCheckBox设置为未选中,也要从构造函数中检查是否在ActionListener方法中选中它true.提前致谢!

包查询;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class Test extends Thread implements ActionListener 
{
    private JButton cancelButton, backButton, startButton;
    private JCheckBox createQueriesCheckBox,createStatisticsFilesCheckBox, createPokerHandIDFilesCheckBox;
    private JFrame frame;

    public void actionPerformed(ActionEvent e)
    {
        if ("Start".equals(e.getActionCommand()))
        {
            if (createQueriesCheckBox.isSelected() == true);
            {
                // Code here
            }

            if (createStatisticsFilesCheckBox.isSelected() == true);
            {
                // Code here
                // Always show as selected …
Run Code Online (Sandbox Code Playgroud)

java swing jcheckbox

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

尽管使用标识符"long",但获取负值/错误值

我试图计算第一个,甚至四百万个斐波那契数的总和.但是,过了一段时间,即使我使用标识符long,只有在值变大时才打印出Y值.

这些是起始值:

long amount = 4000000;
long x = 1;
long y = 2;
long sum = 2;
Run Code Online (Sandbox Code Playgroud)

这是一个for循环,总结并在程序运行时打印出数字.

for (int i = 0; i < amount - 1; i++) {
    if (x > y) {
        y = x + y;
        if (y % 2 == 0) {
            sum += y;
        }           
        System.out.println("X: " + x);
    } else {
        x = x + y;
        if (x % 2 == 0) {
            sum += x;
        }   
        System.out.println("Y: " + y);
    } …
Run Code Online (Sandbox Code Playgroud)

java numbers long-integer

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

Spring重试中的@Retryable注释不会触发

我有一个表更新导致死锁,并试图让Spring重试在方法获得某种锁定异常时重试.我已经尝试取出maxAttempts,值和退避但它似乎永远不会捕获任何异常.我错过了什么吗?我是否需要在Application文件中声明一个bean?任何帮助将非常感激!

Application.Java

@SpringBootApplication
@EnableRetry
public class Application extends SpringBootServletInitializer {
Run Code Online (Sandbox Code Playgroud)

DetailService

@Service
public class DetailService {

    @Retryable(maxAttempts = 5, value = { LockAcquisitionException.class, ConcurrencyFailureException.class }, backoff = @Backoff(delay = 500, multiplier = 2) )
    public void delete(final String detailCode) {
        try {
            this.delete(this.dao.findByDetailCode(detailCode));
        } catch (LockAcquisitionException | ConcurrencyFailureException e) {
            LOG.warn("Locking error! Going to retry", e.getMessage());
            throw e;
        }
    }

    public void delete(Details detail) {
           this.dao.delete(detail);            
    }

    @Retryable(maxAttempts = 5, value = { LockAcquisitionException.class, ConcurrencyFailureException.class }, backoff = @Backoff(delay = …
Run Code Online (Sandbox Code Playgroud)

java spring-retry spring-boot

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

Spring Jackson 数组代替列表

在我的 Spring Boot 应用程序中,我有以下@RestController方法:

@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{decisionId}/decisions/{childDecisionId}/characteristics/{characteristicId}/values", method = RequestMethod.POST)
public ValueResponse create(@PathVariable @NotNull @DecimalMin("0") Long decisionId, @PathVariable @NotNull @DecimalMin("0") Long childDecisionId, @PathVariable @NotNull @DecimalMin("0") Long characteristicId,
        @Valid @RequestBody CreateValueRequest request, Authentication authentication) {
        ....
         request.getValue()
        ...
    }
Run Code Online (Sandbox Code Playgroud)

这是我的CreateValueRequest DTO:

public class CreateValueRequest implements Serializable {

    private static final long serialVersionUID = -1741284079320130378L;

    @NotNull
    private Object value;

...

}
Run Code Online (Sandbox Code Playgroud)

例如,该值可以是String, IntegerDouble以及相应的数组,例如String[], Integer[].. 等

如果是String, Integer, …

java spring jackson spring-restcontroller

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

如何将strtok与每个单个非alpha字符一起用作分隔符?(C)

所以我有一个字符串:

**BOB**123(*&**blah**02938*(*&91820**FOO**
Run Code Online (Sandbox Code Playgroud)

我希望能够用来strtok消除每个单词.分隔符是每个不是字母的单个字符.

我被建议给我们isalpha,但不知道我会怎么做.有没有办法在不指定每个非字母字符的情况下执行此操作?

不幸的是,不允许使用正则表达式库.

c file

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

在没有内置函数的情况下在 Python 中查找字符串的子字符串

我正在尝试编写一些代码来查找字符串中的子字符串。到目前为止,我有这个:

main = "dedicated"
sub = "cat"
count = 0
for i in range (0,len(main)):
   match = True
   if sub[0]==main[i]:
     j=0
     for j in range(0,len(sub)):
         if sub[j]!=main[i+j]:
             match = False
             print "No substring"
             break
         else:
             count=count+1
             if match == True and count == len(sub):
                 print "Substring"
                 print "Position start:",i
Run Code Online (Sandbox Code Playgroud)
  • “奉献”和“猫”作品
  • “这是一个例子”和“例子”返回一个 IndexError
  • “无”和“不同”什么都不返回

任何人都可以帮助我/给我指点/改进代码,使其与上面的要点一起正常工作吗?

python string substring

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

打印数组时的垃圾值

我使用new动态声明数组.数组由字符串长度组成,我从用户那里得到.当我提供7-11之间的长度字符串时,数组正在打印垃圾值.为什么会这样?

#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<climits>
#include<vector>
#include<ctime>
#include<map>
using namespace std;

int main(){
    string str;
    cin>>str;
    int i,j;
    int** arr = new int*[str.length()];
    for(i = 0; i < str.length(); ++i)
        arr[i] = new int[str.length()];

    for(i=0;i<str.length();i++){
        for(j=0;j<str.length();j++){
            cout<<arr[i][j]<<" ";
        }
        cout<<endl;
    }
    return 0;
} 
Run Code Online (Sandbox Code Playgroud)

字符串"BBABCBCAB"的输出是:

36397056 0 8 0 -1 0 1111573058 1094926915 0 
0 0 4 0 -1 0 1111573058 0 0 
0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 …
Run Code Online (Sandbox Code Playgroud)

c++ arrays string new-operator

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

java.lang.NoSuchMethodError:org.apache.spark.ui.SparkUI.addStaticHandler(Ljava/lang/String; Ljava/lang/String;

我正在运行以下关于Java + Spark + SQL的示例.

https://github.com/apache/spark/blob/master/examples/src/main/java/org/apache/spark/examples/sql/JavaSparkSQL.java

但得到这个例外.编译时没有错误

我怎么能避免这个?无法找到有关此例外的任何内容.请帮我.

SparkConf sparkConf = new SparkConf().setMaster("local").setAppName("JavaSparkSQL");
JavaSparkContext ctx = new JavaSparkContext(sparkConf);
SQLContext sqlContext = new SQLContext(ctx);
Run Code Online (Sandbox Code Playgroud)

异常跟踪:

Exception in thread "main" java.lang.NoSuchMethodError: org.apache.spark.ui.SparkUI.addStaticHandler(Ljava/lang/String;Ljava/lang/String;)V
    at org.apache.spark.sql.execution.ui.SQLTab.<init>(SQLTab.scala:36)
    at org.apache.spark.sql.SQLContext$$anonfun$1.apply(SQLContext.scala:79)
    at org.apache.spark.sql.SQLContext$$anonfun$1.apply(SQLContext.scala:79)
    at scala.Option.foreach(Option.scala:257)
    at org.apache.spark.sql.SQLContext.<init>(SQLContext.scala:79)
    at org.apache.spark.sql.SQLContext.<init>(SQLContext.scala:69)
    at org.sun.JavaSparkSQL.main(JavaSparkSQL.java:47)
2015-11-06 18:35:22,834 INFO  org.apache.spark.SparkContext.logInfo:59 - Invoking stop() from shutdown hook
Run Code Online (Sandbox Code Playgroud)

pom.xml依赖项

 <dependency>
     <groupId>org.apache.spark</groupId>
     <artifactId>spark-sql_2.11</artifactId>
     <version>1.5.1</version>
 </dependency>
 <dependency>
     <groupId>org.apache.spark</groupId>
     <artifactId>spark-core_2.11</artifactId>
     <version>1.4.0</version>
 </dependency>
Run Code Online (Sandbox Code Playgroud)

java apache-spark

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

在 Windows 上使用 libssh2 和 libopenssl 的 libgit2

我以前尝试过,但在完整版本中几乎没有成功,但即使现在失败了,而且我显然在 Windows 上遗漏了一些东西(是的,它可能是 Windows :P)

有人可以带我过去吗

  1. 找到正确的 OpenSSL 以使用 libssh2 进行编译
  2. 实际上cmake/将libssh2编译成libgit2,因为它一直说找不到libssh2,我正在努力再次构建它。

我正在使用 CMake gui For windows,尝试构建一个 VC2015 项目

我在构建 libgit2 时遇到的错误是

checking for module 'libssh2'
  package 'libssh2' not found

LIBSSH2 not found. Set CMAKE_PREFIX_PATH if it is installed outside of the default search path.
Run Code Online (Sandbox Code Playgroud)

即使我已经把它放在每一个可能的地方,我认为它会看起来,我试过设置CMAKE_PREFIX_PATH

如果有人在 Windows 上成功完成了它,我将不胜感激一两个关于我做错了什么或应该做什么的指针

谢谢罗伯特

c++ openssl libgit2 libssh2 visual-c++-2015

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

C 生产者/消费者应用程序使用 getenv() 获取环境变量不起作用

我正在编写一个应用程序,生产者负责制作并发送消息,消费者负责接收消息。我必须在生产者应用程序中设置环境变量并在消费者应用程序中读取它。

在生产者应用程序中我执行了这个命令

putenv("MSG_KEY=15");
Run Code Online (Sandbox Code Playgroud)

在消费者应用程序中,我尝试获取这样的变量

char *z=getenv("MSG_KEY");
Run Code Online (Sandbox Code Playgroud)

但它不返回任何值(我得到零值)。如果我在生产者中编写相同的命令,如果我putenv()之前使用几行,它就会起作用。我认为问题在于它仅在本地设置变量,因此我无法从另一个程序访问它,但我不知道如何解决它。不知道这是否重要,但我使用的是Linux系统。

c linux environment-variables getenv

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