小编Ken*_*Ken的帖子

错误:切换数量不是整数

我已经在StackOverflow和多谷歌链接上研究了我的问题,我仍然感到困惑.我认为对我来说最好的事情就是问...

我创建一个简单的命令行计算器.到目前为止,这是我的代码:

const std::string Calculator::SIN("sin");  
const std::string Calculator::COS("cos");  
const std::string Calculator::TAN("tan");  
const std::string Calculator::LOG( "log" );  
const std::string Calculator::LOG10( "log10" );

void Calculator::set_command( std::string cmd ) {

    for(unsigned i = 0; i < cmd.length(); i++)
    {
    cmd[i] = tolower(cmd[i]);
    }

    command = cmd;
}

bool Calculator::is_legal_command() const {

    switch(command)
    {
    case TAN:
    case SIN:
    case COS:
    case LOG:
    case LOG10:
        return true;
        break;
    default:
        return false;
        break;
    }

}
Run Code Online (Sandbox Code Playgroud)

我得到的错误是:

Calculator.cpp: In member function 'bool Calculator::is_trig_command() const':  
Calculator.cpp: error: switch …
Run Code Online (Sandbox Code Playgroud)

c++ string switch-statement constant-expression

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

如何使用 Ctrl-D 终止程序?

我正在尝试编写一个模拟计算器的简单程序。我希望程序在按下Ctrl+D键时退出或关闭。我搜索了 stackoverflow 并看到了Ctrl+CCtrl+ 的其他示例,A但这些示例是在 java 和 C 中的。

对于 C:

(scanf("%lf", &var);
Run Code Online (Sandbox Code Playgroud)

对于 java,按下+SIGINT时会引发a 。 CtrlZ

signal(SIGINT,leave);  
    for(;;) getchar();
Run Code Online (Sandbox Code Playgroud)

我想知道我可以为C++ 中的Ctrl+做什么D...

谢谢大家!

c++ exit-code

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

如何从win32com.client.dispatch获取属性("Shell.Application")

我试图通过python控制我的设备管理器程序(即禁用和重新启用设备).但是,我无法弄清楚"win32com.client.Dispatch("Shell.Application")"命名空间中的属性是什么.我所知道的是获取名称并打印出来.我通过代码进行了调试,但是找不到任何有用的东西.

这是我到目前为止所拥有的

    import win32com.client
    shell = win32com.client.Dispatch("Shell.Application")
    control_panel = shell.Namespace(3)
    for item in control_panel.Items():
        if item.Name == "Device Manager":
            print item
            break
Run Code Online (Sandbox Code Playgroud)

这也不是很有用:

 control_panel.GetNamespace("MAPI")
 Traceback (most recent call last):
   File "<interactive input>", line 1, in <module>
   File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 516, in __getattr__
raise AttributeError("%s.%s" % (self._username_, attr))
 AttributeError: <unknown>.GetNamespace
Run Code Online (Sandbox Code Playgroud)

python windows-7 win32com

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

python不会创建线程?

我可能会遗漏一些愚蠢的东西,但是我已经在pythonwin中运行了我的代码并且它可以工作,但是当我在命令行中运行它时它会怪胎

import time, thread
def print_t(name, delay):
    while 1:
        time.sleep(delay)
        print name
try:
    thread.start_new_thread(print_t,("First Message",1,))
    thread.start_new_thread(print_t,("Second Message",2,))
except Exception as e:
    print e

Unhandled exception in thread started by
sys.excepthook is missing
lost sys.stderr

Unhandled exception in thread started by
sys.excepthook is missing
lost sys.stderr
Run Code Online (Sandbox Code Playgroud)

python windows multithreading

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

C++在函数中的.h文件中重用相同的变量名(this.variable = variable error?)

我的.h文件中有一个变量的名称,该函数具有相同的名称...例如:

//computer.h  
class Computer{  
private:  
    string computerName;  
    int cores;  
}  

//computer.cpp  
Computer::Computer(string computerName, int cores)  
{  
    ...  
}  
Run Code Online (Sandbox Code Playgroud)

我想将.cpp函数中的值赋给.h文件变量.

每当我这样做,它都行不通.我做得对吗?

this.computerName = computerName;  
this.cores=cores;
Run Code Online (Sandbox Code Playgroud)

c++ function this

0
推荐指数
3
解决办法
942
查看次数