小编qua*_*ana的帖子

反向字符串的任何其他方式不使用数组?

int main()  
{  
    clrscr();  
    char c[80],d[80];  
    cout<<"Enter a string = ";  
    cin.get(a,80);  
    strcpy(c,a);  
    strrev(a);  
    if(strcmp(c,a)==0)  
         cout<<"String = "<<c<< "is palindrome.";  
    else  
         cout<<c<<" is not palindrome";  
    getch();  
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

所以有没有其他方法可以轻松地完成这项任务而不使用数组或以其他方式?

c++ algorithm

6
推荐指数
2
解决办法
2414
查看次数

为什么sizeof(int)与sizeof(int*)不同?

我想知道为什么在下面的程序中sizeof(int)返回一个不同的值sizeof(int*).

这是一个小程序:

int main(){
    std::cout<<sizeof(int)<<endl;
    std::cout<<sizeof(int*)<<endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

这是输出:

4
8
Run Code Online (Sandbox Code Playgroud)

直到现在我记得整数指针的大小是4byte(gcc编译器).如何检查指针的正确大小?它依赖于计算机吗?

我正在运行ubuntu 12.04

# lsb_release -a

Distributor ID: Ubuntu 
Description: Ubuntu 12.04 LTS 
Release:    12.04 
Codename:   precise
Run Code Online (Sandbox Code Playgroud)

指针的大小是不是常量(标准大小)8个字节.

c c++ sizeof

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

使用 functools.wraps 装饰器尝试类的每个函数

我试图定义一个装饰器来执行一个类方法,首先尝试它,如果检测到错误,则提出它并提及失败的方法,以便用户可以看到哪个方法是错误的。

在这里,我展示了我的代码的MRE(最小的、可重现的示例)。

from functools import wraps

def trier(func):
    """Decorator for trying A-class methods"""
    @wraps(func)
    def inner_func(self, name, *args):
        
        try:
            func(self, *args)
        
        except:
            print(f"An error apeared while {name}")
    
    return inner_func
    
class A:
    def __init__(self):
        self._animals = 2
        self._humans = 5
    
    @trier('getting animals')
    def animals(self, num):
        return self._animals + num
    
    @trier('getting humans')
    def humans(self):
        return self._humans

A().animals
Run Code Online (Sandbox Code Playgroud)

出现许多错误,例如:

类型错误:inner_func() 缺少 1 个必需的位置参数:“名称”

或者误解 self class 与 self function 。

python decorator wrapper functools

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

您实际使用哪些技术来改善代码覆盖率?

我经常使用TDD实现100%的库覆盖率,但并非总是如此,并且似乎总是存在未经测试和未发现的应用程序部分.
然后有一些情况,当你从遗留代码开始,它只有很少的测试和很少的覆盖率.

请说出你的情况是什么,以及至少改善了覆盖面的工作.
我假设您在单元测试期间测量覆盖率,但是如果您正在使用其他技术.

language-agnostic code-coverage

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

如何为具有std :: stringstream成员的类编写复制构造函数?

如果我有这样的类,我该如何编写复制构造函数?

#include <stringstream>

class MyClass {
  std::stringstream strm;
public:
  MyClass(const MyClass& other){
    //...
  }
  std::string toString() const { return strm.str(); }
};
Run Code Online (Sandbox Code Playgroud)

std :: stringstream本身没有复制构造函数,所以我不能使用这样的初始化列表:

MyClass(const MyClass& other): strm(other.strm) {}
Run Code Online (Sandbox Code Playgroud)

c++ stl

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

如何管理水晶报表中的页面大小和边距?

我是水晶报告的新手,并使用.Net(WinForm/Visual Studio 2010)的水晶报告.

我在想如何在报告中设置页面大小以及顶部,底部,左侧和右侧边距.我试图看看选项,但无法得到它.请指导我.

.net c# crystal-reports winforms

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

自动初始化后变量的大小

#include <iostream>
#include <math.h>

using namespace std;

int main() {
    int    i{100};
    float  f{3.14};
    double d{3.14159};
    cout<<"size of int is: "   <<sizeof(i)<<endl;
    cout<<"size of float is: " <<sizeof(f)<<endl;
    cout<<"size of double is: "<<sizeof(d)<<endl<<endl;;

    auto x = sin(3.14159);
    cout<<"size of auto that is double is: "<<sizeof(x)<<endl<<endl;

    auto y{sin(3.14159)};
    cout<<"size of auto that is double is: "<<sizeof(y)<<endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出是:

int的大小是:4

浮动的大小是:4

双倍的大小是:8

auto的大小是双倍的:8

auto的大小是双倍的:16

为什么是sizeof(y)16?

c++ initializer-list auto c++11 type-deduction

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

什么代表这个pharo类图标?

我看到不同类别的不同图标,如下图所示:

浏览器窗格

这是什么意思?其中一些带有红色图标的我可以添加注释,但是例如带有"c"和"ray"的那些不允许我.

这些评论提到了类责任合作者(CRC)设计,但不清楚评论如何影响图标.

smalltalk pharo

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

重载的++运算符在c ++中不起作用

有人可以向我解释为什么我的重载++(预版本)没有更新值吗?片段是这样的:

circle circle:: operator++()
{  
    Area = Area * 2.0;
    return *this; 
}
/////////////////////////////

int main()
{
    class circle c1(4, 1, -1), c2(12, 4, 6);
    c1.output();
    c1++;
    c1.output();

    system("pause");
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++

5
推荐指数
2
解决办法
751
查看次数

__repr__ method appears can't be invoked automatically for Exception class

I was told that if an obj's __str__ method isn't created but __repr__ is created then printing the obj will invoke __repr__. That appears to be true for normal class, but when I try it on Exception's subclass, it is weird that __repr__ doesn't get invoked, could anyone explain why?

Here's an example

class BoringError(Exception):
  def __init__(self):
    self.purpose = "Demonstration"
    self.boringLevel = 10
  def __repr__(self):
    return "I'm a message for developer"

 try: 
   if 1 != 2:
    raise BoringError 
 except …
Run Code Online (Sandbox Code Playgroud)

python python-3.x

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