小编ene*_*dil的帖子

typeinfo/typeid输出

我目前正在尝试调试一段简单的代码,并希望看到特定的变量类型在程序中如何变化.

我正在使用typeinfo头文件,所以我可以使用typeid.name().我知道typeid.name()是特定于编译器的,因此输出可能不是特别有用或标准.

GCC假设存在一个typeid输出符号列表,我正在使用但是我找不到尽管搜索的潜在输出列表.我不想根据输出进行任何类型的转换或操纵任何类型的数据,只需按照其类型.

#include <iostream>
#include <typeinfo>

int main()
{ 
    int a = 10;
    cout << typeid(int).name() << endl;
}
Run Code Online (Sandbox Code Playgroud)

在任何地方都有符号列表吗?

c++ gcc types

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

如何在Python中的一行中输入2个整数?

我想知道是否可以在一行标准输入中输入两个或更多整数.在C/ C++它很容易:

C++:

#include <iostream>
int main() {
    int a, b;
    std::cin >> a >> b;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

C:

#include <stdio.h>
void main() {
    int a, b;
    scanf("%d%d", &a, &b);
}
Run Code Online (Sandbox Code Playgroud)

Python,它将无法工作:

enedil@notebook:~$ cat script.py 
#!/usr/bin/python3
a = int(input())
b = int(input())
enedil@notebook:~$ python3 script.py 
3 5
Traceback (most recent call last):
  File "script.py", line 2, in <module>
    a = int(input())
ValueError: invalid literal for int() with base 10: '3 5'
Run Code Online (Sandbox Code Playgroud)

那怎么办呢?

python input line python-3.x

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

perl以4位数字格式打印当前年份

我如何得到4位数的当前年份这是我试过的

 #!/usr/local/bin/perl

 @months = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
 @days = qw(Sun Mon Tue Wed Thu Fri Sat Sun);
 $year = $year+1900;
 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
 print "DBR_ $year\\$months[$mon]\\Failures_input\\Failures$mday$months[$mon].csv \n";
Run Code Online (Sandbox Code Playgroud)

这打印 DBR_ 114\Apr\Failures_input\Failures27Apr.csv

我如何获得2014年?

我正在使用版本5.8.8 build 820.

perl

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

用Python计算e

表示以下等式的最简单方法是什么?

只是为了澄清,我的问题是要求一些代码来计算方程式的答案。

这有两个问题:

  1. 求和保证了无限循环,不可能从中得到答案

  2. 我希望得到一个长而详细的答案(也许是40位左右)。

python math python-3.x

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

类型推断规则

我试图使一个函数接受两个字符,并接受其ASCII值并返回其XOR。当然,这可行:

> let a, b = '#', '%' in (int a) ^^^ (int b);;
val it : int = 6
Run Code Online (Sandbox Code Playgroud)

但是,这会使函数采用整数,而这里不是这种情况。

> let xor a b  = (int a) ^^^ (int b);;                        

val xor : a:int -> b:int -> int
Run Code Online (Sandbox Code Playgroud)

不出所料,我无法在以前的参数上调用此函数:

> let a, b = '#', '%' in xor a b;;

  let a, b = '#', '%' in xor a b;;
  ---------------------------^

/home/cos/stdin(121,28): error FS0001: This expression was expected to have type
    int    
but here has type
    char    
Run Code Online (Sandbox Code Playgroud)

为什么会发生?如何直接指定参数类型?

syntax f# types

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

错误C2601:'main':本地函数定义是非法的 - MS VS 2013编译器

我正在用C++编写一个小程序.当我尝试使用MS VS 2013编译器编译它时,我收到一个错误:"C2601:'main':本地函数定义是非法的".这是什么意思?我的代码是:

#include <iostream>
int n;
int pomocniczaLiczba;
using namespace std;
int ciong(int n){
    switch (n)
    {
    case 1:
        return 1;
        break;
    case 2:
        return 2;
        break;
    default:
        pomocniczaLiczba = ciong(n - 2) + ciong(n - 1) * ciong(n - 1);
        return pomocniczaLiczba;
        break;
    }
int main()
{
    cin >> n;
    cout >> ciong(n);
    return 0;
}
}
Run Code Online (Sandbox Code Playgroud)

c++ visual-c++

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

标签 统计

c++ ×2

python ×2

python-3.x ×2

types ×2

f# ×1

gcc ×1

input ×1

line ×1

math ×1

perl ×1

syntax ×1

visual-c++ ×1