小编M_M*_*M_M的帖子

wprintw:在ncurses中,当写入与窗口宽度完全相同的换行符终止行时,会打印两个换行符

我刚刚完成了 CLI 程序的代码,并使用 ncurses 将其转换为 TUI 程序。

它以类似于抽认卡的方式测试用户的一系列问题和答案。

除了我用弹出窗口的函数替换了许多printf()调用之外,一切都进行得相对顺利。 该函数使用以下函数:popupinfo(int colour,char * title, char * body)

int textwidth (char * text);//returns the width of a given string (which may include newlines) in chars when displayed without wrapping (for purposes of determining optimum window width)
int textheight (char * text, int width);//returns the height of a given string (which may include newlines) in lines when displayed wrapped to the given width (for purposes of determining optimum window width) …
Run Code Online (Sandbox Code Playgroud)

c newline ncurses

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

使用 Go (golang)、cobra 和 viper 时,StringVar 与 StringVarP 或 String 与 StringP 之间有什么区别?

我正在维护一些使用 Go (golang)、ViperCobra编写的代码。

一方面,它有:

rootCmd.PersistentFlags().String("cfg", "", "A description")
Run Code Online (Sandbox Code Playgroud)

然后在下一行它有

rootCmd.PersistentFlags().StringP("output", "o", ".", "Another description")
Run Code Online (Sandbox Code Playgroud)

在这种情况下StringStringP在这种情况下有什么区别?

查看各种教程中的示例用法,似乎有各种方法的版本P和非P版本,例如StringVarPStringVar

这些版本之间有什么区别?的意义P何在?

有没有一种方法可以判断给定的方法是否具有对应物P或非P对应物?

搜索引擎倾向于将我带到 cobra 或 viper 教程页面,这些页面使用这些方法而不解释P或非P对应。

我发现一些材料pflags表明它可能与参数是否具有短(一个字母)形式有关。会是这样吗?

编辑后说明:收到这个问题的答案后,spf13/pflag上面提到的 golang 框架似乎确实在幕后使用了它。然而,在使用 cobra 或 viper 时是否应该查看 pflags 文档并不清楚。
由于这是一个问答网站,我已经恢复了一项编辑,该编辑删除了我在寻找此答案时会输入的许多关键字,因为我觉得其他人在寻找相同的信息时会以这种方式得到更好的服务。

go viper-go go-cobra

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

尝试使用valgrind的输出调试ac程序分段错误

我的CLI程序在windows上编译并运行良好.在linux上编译很好,但在运行时会导致分段错误.

我转向stackoverflow寻求帮助,发现了一些类似于我要问的建议valgrind的问题,我刚刚安装了它(哇!).

所以我通过valgrind运行我的程序,得到了令人沮丧的大量输出,但我将从第一条错误消息开始:

==11951== Command: ./vt
==11951== 
Loading...
Load default database? (y/n)y
Opened input file vtdb.~sv, reading contents...
==11951== Invalid write of size 1
==11951==    at 0x400FA9: readnumberfromfile (in /home/rob/Documents/programming/c/vocabtest/vt)
==11951==    by 0x400C21: getrecordsfromfile (in /home/rob/Documents/programming/c/vocabtest/vt)
==11951==    by 0x401FFD: main (in /home/rob/Documents/programming/c/vocabtest/vt)
==11951==  Address 0x53b05bb is 0 bytes after a block of size 11 alloc'd
==11951==    at 0x4C28FAC: malloc (vg_replace_malloc.c:236)
==11951==    by 0x400EAC: readnumberfromfile (in /home/rob/Documents/programming/c/vocabtest/vt)
==11951==    by 0x400C21: getrecordsfromfile (in /home/rob/Documents/programming/c/vocabtest/vt)
==11951==    by 0x401FFD: main (in /home/rob/Documents/programming/c/vocabtest/vt)
==11951== 
...finished. …
Run Code Online (Sandbox Code Playgroud)

c debugging valgrind segmentation-fault

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

"git checkout - "有什么区别?和"git reset HEAD --hard"?

这不是关于' - '的一般问题,如标记的副本.这是一个特定于git的问题,要求明确所提到的命令之间的操作差异.

如果我想清除当前目录而不进行存储或提交,我通常会使用以下命令:

git reset HEAD --hard
git clean -fd
Run Code Online (Sandbox Code Playgroud)

一位同事还提到使用这个命令:

git checkout -- .
Run Code Online (Sandbox Code Playgroud)

对谷歌来说这是一个困难的命令,而且从git文档中我不清楚这个命令实际上做了什么.它似乎是手册中后面提到的用法之一.

猜测它会复制git reset HEAD --hard,但与我已经使用的命令相比,它究竟做了什么呢?
它是复制一个还是两个命令,还是相似但略有不同?

git git-checkout git-reset git-clean

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

头文件中的代码似乎会导致编译错误

我有一个CLI程序,该程序由一个vt.c文件组成,该文件可以使用Open Watcom在Windows(cmd.exe)下编译并运行。我还可以在Windows上运行Open Watcom时为Linux编译它(并且生成的版本在Linux下运行)。

但是,当我尝试在linux下编译它时(使用make,它调用cc),我收到375行错误消息。以下是其中一些,其中许多后续错误类似,我只粘贴了前几个:

In file included from vt.c:4:0:
process.h: In function ‘__declspec’:
process.h:45:22: error: storage class specified for parameter ‘execl’
process.h:46:1: error: expected declaration specifiers before ‘__declspec’
process.h:47:1: error: expected declaration specifiers before ‘__declspec’
...
In file included from vt.c:5:0:
ctype.h:48:1: warning: empty declaration
ctype.h:81:37: error: storage class specified for parameter ‘__ctype_b_loc’
ctype.h:82:6: warning: ‘__nothrow__’ attribute ignored
ctype.h:83:28: error: storage class specified for parameter ‘__ctype_tolower_loc’
ctype.h:84:6: warning: ‘__nothrow__’ attribute ignored
ctype.h:85:28: error: storage class specified for parameter ‘__ctype_toupper_loc’
ctype.h:86:6: …
Run Code Online (Sandbox Code Playgroud)

c linux compiler-errors header-files

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

Perl 中的美元插入符零变量 ( $^0 ) 是什么?

我发现了一些进行以下检查的 Perl 代码:

如屏幕所示

if ($^O eq 'MSWin32')
Run Code Online (Sandbox Code Playgroud)

$^0变量是什么?看起来它包含运行它的机器的体系结构/操作系统,但我不知道这是否是在脚本中其他地方分配它的结果(也许它是正则表达式匹配的结果,尽管我看不到任何在该点之前执行的匹配操作),或者该变量是否始终具有与其运行的机器相关的值。

我想检查运行脚本的机器的操作系统和位数,并想知道我是否可以使用 $^0 来帮助我(如果不是,那么我仍然很好奇它是什么)。

我宁愿不发布 Perl 脚本的其他部分,因为它是专有的。

这让我觉得应该是以前应该问过的那种问题,但是由于特殊字符,Google 没有多大用处(我经常认为无法使用 Google Perl 代码在一定程度上导致了它的消亡),而 Stack Overflow 没有也没有任何有用的建议问题。

perlvar页面上没有 $^0 或 $^1 或 $^# 匹配项,我不相信 $^N 或 $^X 是相关的。

perl special-variables

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

聚合'QSqlQuery testQuery'具有不完整的类型,无法定义

我敢肯定这一定很简单,但我不能弄清楚这里有什么......

我正在尝试创建一个QSqlQuery,编译器正在给我这个:

error: aggregate ‘QSqlQuery testQuery’ has incomplete type and cannot be defined

这段代码在我的mainWindow类中:

void MainWindow::on_toolButton_clicked()
{
    QString filename;
    filename = QFileDialog::getSaveFileName(this, tr("Save to SQL Database"),
                                            "~/temp",
                                            tr("Files (*.fdb)"));
    QSqlDatabase testDatabase = QSqlDatabase::addDatabase("QSQLITE");
    testDatabase.setDatabaseName(filename);

    //this line won't compile:
    QSqlQuery testQuery;

    testDatabase.close();
    QSqlDatabase::removeDatabase(QSqlDatabase::database().connectionName());
}
Run Code Online (Sandbox Code Playgroud)

谁能看到我在这里失踪的东西?

sql qt4 incomplete-type

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

多态类的行为不符合预期

我正在编写一些arduino代码,但事情并没有完全按计划进行.
我在这做错了什么?我已经阅读并尝试了解虚拟功能,但也许我错过了一些东西.转到QUESTIONSHERE以获取我需要答案的实际问题,但首先是一些解释:

类RGBPixel和colorGenerator都派生自colorSource,它提供公共函数getR(),getG()和getB(),以便另一个像素或颜色修饰符可以获取其当前颜色的副本.
从colorGenerator派生的类实现颜色生成代码,以便它们可以生成自己的颜色,而RGBPixels具有colorSource*父成员,因此它们可以从colorGenerator或另一个RGBPixel获取颜色值.
在我的例子中,我有一个colorGenerator子类(CG_EmeraldWaters,它应该创建各种绿色和蓝色),然后是一个数组中的一些RGBPixel.RGBPixels [0]应该从GC_EmeraldWaters的实例获取其值,而RGBPixels [1]从[1]中获取其值,从[1]中获取[2],从[n-1]获取[n].像素似乎从它们的父项中拉出一种颜色就好了,但是链中的第一个像素没有正确查询colorGenerator,或者colorGenerator没有正确更新.

要更新colorGenerator,colorController类会监视整个过程:

colorController.h:

#ifndef _COLORCONTROLLER_H
#define _COLORCONTROLLER_H

#include <list>
#include "colorGenerator.h"
#include "RGBPixel.h"
#include "globals.h"
#include "Arduino.h"

unsigned long millis();

typedef std::list<colorGenerator> generatorList;

class colorController
{
    public:
    virtual bool refresh();
    protected:
    generatorList generators;
};

#endif //_COLORCONTROLLER_H
Run Code Online (Sandbox Code Playgroud)

如您所见,控制器有一个colorGenerators列表和方法来刷新它们(从loop()调用),除非在子类中重写,否则执行以下操作:

bool colorController::refresh()
{
    for (generatorList::iterator it = generators.begin(); it != generators.end(); ++it)
    it->refresh();
    bool dirty = false;
    for (int i = NUM_OF_LEDS-1; i >= 0; --i)
    dirty |= RGBPixels[i].refresh();
    return dirty;
}
Run Code Online (Sandbox Code Playgroud)

CC_Cascade类(派生自colorController)设置如下:

CC_Cascade.h

#ifndef _CC_CASCADE_H
#define …
Run Code Online (Sandbox Code Playgroud)

c++ polymorphism inheritance arduino

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