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)
所以有没有其他方法可以轻松地完成这项任务而不使用数组或以其他方式?
我想知道为什么在下面的程序中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个字节.
我试图定义一个装饰器来执行一个类方法,首先尝试它,如果检测到错误,则提出它并提及失败的方法,以便用户可以看到哪个方法是错误的。
在这里,我展示了我的代码的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 。
我经常使用TDD实现100%的库覆盖率,但并非总是如此,并且似乎总是存在未经测试和未发现的应用程序部分.
然后有一些情况,当你从遗留代码开始,它只有很少的测试和很少的覆盖率.
请说出你的情况是什么,以及至少改善了覆盖面的工作.
我假设您在单元测试期间测量覆盖率,但是如果您正在使用其他技术.
如果我有这样的类,我该如何编写复制构造函数?
#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) 我是水晶报告的新手,并使用.Net(WinForm/Visual Studio 2010)的水晶报告.
我在想如何在报告中设置页面大小以及顶部,底部,左侧和右侧边距.我试图看看选项,但无法得到它.请指导我.
#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"和"ray"的那些不允许我.
这些评论提到了类责任合作者(CRC)设计,但不清楚评论如何影响图标.
有人可以向我解释为什么我的重载++(预版本)没有更新值吗?片段是这样的:
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) 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)