小编use*_*840的帖子

如何使用egrep查找具有2个连续相同字符的单词?

我试图用蛮力的方式做到这一点:

egrep '[a][a] | [b][b] | [c][c]....' file
Run Code Online (Sandbox Code Playgroud)

有没有更好的方法呢?

unix grep

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

为什么不调用移动构造函数

所以我是新手移动语义,我正在测试以下代码.我的理解是rvalue将调用移动构造函数,我期望A("123")将导致移动构造函数被调用.但是当我运行它时,会调用复制构造函数.

#include <string>
#include <iostream>
#include <utility>

class  A
{
    std::string s;
    public:

    A(const std::string& in) : s(in) { std::cout << "ctor!\n";}
    A(const A& o) : s(o.s) { std::cout << "move failed!\n"; }
    A(A&& o) noexcept : s(std::move(o.s)) { }
};

class  B
{
    A d_a;
    public:
    B(const A& a) :d_a(a)
{}
};

int main()
{
    std::cout << "Trying to move A\n";
    B b(A("123")); // move-constructs from rvalue temporary

}
Run Code Online (Sandbox Code Playgroud)

c++

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

如何在构造函数外添加Jlabel到Jpanel?

我可以使用add(new Jlabel())在Jpanel构造函数中的Jpanel上创建标签,但是一旦我使用其他函数调用add(),标签就不会显示在面板上.我做错了什么?

public class DisplayPanel extends JPanel {


        JLabel headerField = new JLabel("Choose a file to generate report.");

        JLabel dateField = new JLabel("123");
        JLabel meanField = new JLabel("");

        JLabel minField = new JLabel("");

        JLabel maxField = new JLabel("");

        JLabel stdDevField = new JLabel("");

        public DisplayPanel() {
        super();
                setBackground(Color.white);
                setLayout(new GridLayout(6, 1));


        add(headerField);
        **//add(new JLabel("123")); this will work**

        }


        public void setFields(DataManager d)
        {
            dateField.setText(d.getStartDate() + " - " + d.getEndDate());
            meanField.setText("Mean: " + d.getMean());
            minField.setText("Min: " + d.getMin());
            maxField.setText("Max: " …
Run Code Online (Sandbox Code Playgroud)

java swing jlabel

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

哪一个更快/更容易排序?数组或链表?

我正在编写一个需要使用数组或链表存储数据的项目.稍后,必须对数据进行排序.我觉得编码数组更容易排序,因为我们只是交换.对于链接List,我们不得不担心(和代码)有关指针和访问每个元素比数组更昂贵.我对吗?

c

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

如何在printf()中使用绝对填充?

我试过了

printf("%s %15s", string1, string2);
Run Code Online (Sandbox Code Playgroud)

我发现这种左边的填充取决于距离第一个字符串的距离,如果我想从左边开始计算一个绝对的左边填充怎么办?

c

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

为什么我能摆脱seg.如果我把printf()错了?

我的程序有一些列表处理函数,一切正常,直到我添加了reverseLinkedList函数.我观察到有一个段.错误错误,后来我通过添加printf()"解决"错误想出来了,但我不知道为什么.

这是代码的片段:

NODE *list_B;
void functionA();

int main ( )
{
..


   functionA();
   printf("O.o\n");// <=== if I add this line, the seg. fault is gone. Without it, I got the error
   printSummary(); //this is just printing out whatever is in list_B
}
void functionA()
{
   list_B = reverseLinkedList(list_B);
}

NODE* reverseLinkedList(NODE *head) //this is implemented in other head file.
{
    NODE *current = NULL;
    NODE *temp;

    while(head != NULL)
    {
        temp = head;
        head = head->next;
        temp->next = current;
        current …
Run Code Online (Sandbox Code Playgroud)

c

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

在分配操作员上遇到麻烦

嗨,我在Android中使用AI进行棋盘游戏.

我遇到了一种对我没有意义的情况.

码:

    for(int y = 0; y < BOARD_SIZE ; y++)
    {
        Log.i(TAG, "before calling virtual mBoard:" + mBoard[y]);
    }

    virtualBoard = mBoard;  // int arrays
    virtualBoard[x] = nextMove(counter);

    for(int j = 0; j < BOARD_SIZE ; j++)
    {
        Log.i(TAG, "before calling AIValue mBoard:" + mBoard[j]);
    }
Run Code Online (Sandbox Code Playgroud)

当我使virtualBoard等于mBoard时,我只是将一个数组分配给另一个数组,但为什么日志不同?怎么可能?

java arrays android

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

为什么我们在pimpl中使用'new'?

我正在研究如何在C++中使用pimpl,我在教程中找到了这段代码:

// In MyClass.h

class MyClassImp;                    // forward declaration of Pimpl

class MyClass
{
public:
   MyClass ();
   ~MyClass();

   MyClass( const MyClass &rhs );   // undefined for simplicity
   MyClass& operator=( MyClass );

   void  Public_Method();

private:
   MyClassImp *pimpl_;              // the Pimpl
};

// In MyClass.cpp

#include "MyClass.h"

class MyClassImp
{
public:
   void   Private_Method()  {}  // dummy private function

   int    private_var_;            // a private variable
};

MyClass::MyClass()  :  pimpl_( new MyClassImp() )
{
}

MyClass::~MyClass()
{
   delete  pimpl_;
}

void   MyClass::Public_Method()
{
   pimpl_->Private_Method(); …
Run Code Online (Sandbox Code Playgroud)

c++

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

标签 统计

c ×3

c++ ×2

java ×2

android ×1

arrays ×1

grep ×1

jlabel ×1

swing ×1

unix ×1