小编Bil*_*nch的帖子

用C语言递归声明函数

从adream307得到一个问题,我不知道,你呢?

我想声明一个这样的函数:(我们将这种类型的函数命名为F)

  1. F的返回类型是"无效"
  2. F的参数是一个函数指针,该指针指向一个类型与F相同的函数

我可以声明这样的函数吗?

c recursion compilation function declare

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

正则表达式只匹配5个字母的单词

我有一个数组,只想检索5个字母的单词,不再是,我试图使用

$new = preg_grep("/.{5}/", $array);
Run Code Online (Sandbox Code Playgroud)

但这导致任何至少5个字母的单词.我想要任何最多5个字母的单词.

regex

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

如何为架构x86_64错误修复g ++未定义符号?

首先,我已经在Stackoverflow上阅读了有关此问题的相关内容,但我仍然无法解决它.我尽可能简化了我的代码.

我只有一个带.h和.cpp文件的自定义类,但是在尝试从main.cpp创建此类的实例时出错.

main.cpp中

#include "Customer.h"
using namespace std;

int main() {
    Customer a("string");

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

Customer.h

using namespace std;

class Customer {
public:
    Customer(string input);
};
Run Code Online (Sandbox Code Playgroud)

为customer.cpp

#include "Customer.h"
using namespace std;

Customer::Customer(string input) {
}
Run Code Online (Sandbox Code Playgroud)

我得到的错误信息如下?

  gcc *.cpp -o k


  Undefined symbols for architecture x86_64:
    "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__init(char const*, unsigned long)", referenced from:
        _main in main-40340f.o
    "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::basic_string(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
        _main in main-40340f.o
    "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()", referenced from:
        _main in …
Run Code Online (Sandbox Code Playgroud)

c++ string macos gcc

3
推荐指数
2
解决办法
8091
查看次数

在python中,为什么只有在调用另一个模块的方法时才会执行类体中的代码?

与Java不同,在python中将模块导入另一个模块并调用模块的方法时,为什么主体中的代码会被执行而不是只执行方法中的代码?

示例(取自另一个SO问题):

提交one.py

def func():
    print("func() in one.py")

print("top-level in one.py")

if __name__ == "__main__":
    print("one.py is being run directly")
else:
    print("one.py is being imported into another module")
Run Code Online (Sandbox Code Playgroud)

文件two.py

import one

print("top-level in two.py")
one.func()

if __name__ == "__main__":
    print("two.py is being run directly")
else:
    print("two.py is being imported into another module")
Run Code Online (Sandbox Code Playgroud)

当我运行这个:

python two.py
Run Code Online (Sandbox Code Playgroud)

我明白了:

top-level in one.py
one.py is being imported into another module
top-level in two.py
func() in one.py
two.py is being run directly
Run Code Online (Sandbox Code Playgroud)

如果我只想要执行的func()方法, …

python

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

在字典中对小数进行排序

我几乎完成了我的排序问题,在网上浏览了很多时间我偶然发现了一个非常有用的指导,在Python中对字典进行排序,但是每当我尝试排序时似乎重复出现的问题是我需要排序的数据是浮点数据类型.

我如何创建'names'x''和'avmph'x''变量的示例

file1=open("1.txt",'r')
line1=file1.readlines()
names1=line1[0].rstrip('\n')
avmph1=line1[3].rstrip('\n')

mydict={names1:avmph1,
    names2:avmph2,
    names3:avmph3,
    names4:avmph4,
    names5:avmph5,
    names6:avmph6,
    names7:avmph7,
    names8:avmph8,
    names9:avmph9,
    names10:avmph10}

for key, value in sorted(mydict.items(),key=lambda item:(item[1],item[0])):
    print ("%s : %s" % (key,value))
Run Code Online (Sandbox Code Playgroud)

我得到的结果如下:

1987dodd : 10
3219guy : 11.6
2198adams : 12.2
8765james : 13.2
4321jones : 6.3
5432kane : 6.3
9876smith : 6.5
8754smith : 8.7
7654max : 9
6543dunne : 9.5
#seems to sort values that are greater than 10 (2 digits before decimal) separately 
Run Code Online (Sandbox Code Playgroud)

我不确定如何编辑我现有的代码,因为.sort(float)单独在我的'avmph'上工作,这个方法应该允许我返回'names'和'avmph'.任何帮助都是非常有用的.

python sorting floating-point dictionary decimal

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

如何反转堆栈

我有一个任务,我假设采取一个堆栈,显示输出,然后反转它以显示输出.

它假设看起来像这样

Stack:
262 115 74 26 34 243 22 734 113 121
Stack Reversed:
121 113 734 22 243 34 26 74 115 262
Run Code Online (Sandbox Code Playgroud)

相反,我的出现就像这样

Stack:
262 115 74 26 34 243 22 734 113 121 121 113 734 22 243 34 26 74 115 262
Stack Reversed:
Run Code Online (Sandbox Code Playgroud)

有人可以看看我的代码,看看发生了什么.我已经尝试了很多东西,但无法完成任何工作.

#include <stdio.h>
#include <iostream>

#include "linkedStack.h"

using namespace std;

template <class Type>
void printStack(linkedStackType<Type>& stack);

template <class Type>
void reverseStack(linkedStackType<Type>& stack);

int main(int argc, char **argv)
{
   // Declare stack …
Run Code Online (Sandbox Code Playgroud)

c++ stack

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

OpenCVAndroid Imgproc.GaussianBlur应用程序已停止

我是新手OCV和android开发者.我想在我的应用程序中使用Imgproc.GaussianBlur过滤器.当我使用它时,应用程序发送"应用已停止".我只在"OpenCV Tutorial 3 - Camera Control"中添加了3行:

public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
    Mat mat = inputFrame.gray();
    org.opencv.core.Size s = mat.size();
    Imgproc.GaussianBlur(mat, mat, s, 2);
    return mat;
}
Run Code Online (Sandbox Code Playgroud)

可能有什么不对?我有联想A820 Android 4.1.2并在OpenCV 2.4.4,2.4.5和2.4.6上试用过它.我尝试了不同的API.该Imgproc.Sobel(mat,mat,-1,1,1);过滤器工作良好.

android opencv gaussian filter

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

c中fscanf返回值的问题

我很抱歉这样做的问题(因为互联网上有这么多关于此问题),但我不得不问这个问题:

练习涉及从带有学生列表的文件中读取(记录包含:姓名,姓氏和序列号).我已经创建了文档并由13行组成,但是当我在终端上写入时./a.out,输出是这种类型的13行的列表:(null) (null) (null)

代码是:

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#define EOF (-1)
#define BUF 100

typedef struct stud{
    char *surname;
    char *name;
    char *serial;
} student;

int main(void){
    FILE *fd;
    int n = BUF;
    int k = 0;
    int i = 0;
    int ret;
    char *s = malloc(BUF * sizeof(char));
    if((fd = fopen("registry_office_students.txt","r")) == NULL){
        perror("error opening file");
        return -1;
    }
    while(fgets(s,n,fd)!=NULL){
        k++;
    }
    student *a = malloc(k*sizeof(student));
    rewind(fd);
    ret = fscanf(fd, "%s, %s, %s", …
Run Code Online (Sandbox Code Playgroud)

c scanf return-value

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

C++ substring似乎指向了错误的位置

我正在用C++阅读一个文本文件.由于我是C++的新手,我添加了一堆"cout"语句来查看事物的行为.我得到了一个输出,我没有找到任何解释,希望这里有人能指出我的相关文字.

  1. 我读了一行
  2. 打印线
  3. 使用"substr()"在"line"中打印前2个字符
  4. 将该行复制到工作区("mybuffer")
  5. 打印我工作区的子字符串,长度为10个字符

问题:(a)(3)的输出似乎是一个转义序列(不可打印的字符).如果我将子串的长度从2更改为4,我得到一个/.(b)即使"mybuffer"的内容看起来正确(前两个字符确实是//),子字符串函数只返回七个(可打印的)字符.

while( std::getline( file, line ) )
{
foundeq = 0;
clearthis = 0;
mybuffer = line;
cout<< "line>>" << line<<"\n";
cout<<"first 2 chars in line>>"<<line.substr(0,2)<<"\n";
cout<< "mybuffer>>" << mybuffer<<"\n";
cout<<"first 10 chars in mybuffer>>"<<mybuffer.substr(0,10)<<"\n";
Run Code Online (Sandbox Code Playgroud)

输出:

    line>>//--------------------------------------------------
    first 2 chars in line>>\357\273
    mybuffer>>//--------------------------------------------------
    first 10 chars in mybuffer>>//-----
Run Code Online (Sandbox Code Playgroud)

到底是怎么回事??

提前感谢您的意见.

c++ string substr

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

关于删除指针的 Clang 警告

我开始使用 clang 来替代 gcc。但是当我删除[]指针时,它会发出警告。但当我改变时,警告就消失了。为什么以及如何处理?

int *a = new int[1];
int *b = new int[1];
delete[] a, b;
Run Code Online (Sandbox Code Playgroud)
a.cpp:7:17: warning: expression result unused [-Wunused-value]
    delete[] a, b;
Run Code Online (Sandbox Code Playgroud)
a.cpp:7:17: warning: expression result unused [-Wunused-value]
    delete[] a, b;
Run Code Online (Sandbox Code Playgroud)

没有警告。

c++ clang

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