小编pro*_*eek的帖子

python异常与C++异常处理

使用以下代码,我得到了"Gotcha!" 用python.

try:
    x = 0
    y = 3/x
except Exception:
    # ZeroDivisionError
    print "Gotcha!"

我认为这是等效的C++代码,但它无法捕获该异常.

#include <iostream>

int main()
{
  int x = 0;
  //float y = 3.0/x;
  int z = 0;

  try {
      z = 3 / x;
  } catch (std::exception) {
      std::cout << "Gotcha!";
  }

  std::cout << z;
}
Run Code Online (Sandbox Code Playgroud)
Floating point exception

什么地方出了错?我怎么能抓住这个例外?

c++ exception-handling

0
推荐指数
1
解决办法
774
查看次数

如何控制emacs中的变量?

组织模式手册第49页有以下注释.

"To limit tag inheritance to specific tags, or to turn it off entirely, use the variable org-use-tag-iheritance and org-tags-exclude-from-inheritance." 

看来我应该将这些变量设置为emacs中的1或t.它是否正确?如果是这样,我该怎么做?

emacs

0
推荐指数
1
解决办法
105
查看次数

if __name__ =="__ main __":C#中的等价物

使用python,我可以if __name__ == "__main__":将模块用作库和程序.

  • 我可以在C#中模仿这个功能吗?

我看到C#中的一个类可以有一个'static void Main()',但是我不确定每个类是否都可以有一个没有问题的Main().

添加

/ m:CLASS_NAME是一种指定运行Main()的类的方法.

c# python

0
推荐指数
2
解决办法
614
查看次数

如何为类中的类设置css?

使用此HTML代码.

<div class="noote">
    <p class="first admonition-title">Noote</p>
    <p class="last">Let's noote.</p>
</div>
Run Code Online (Sandbox Code Playgroud)

如何用css将Noote的颜色设置为红色?我的意思是,如何用css为它设置(div class ="noote")和(p class ="first")?

html css css-selectors

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

如何打印出子进程使用C#打印的值?

正如问到这个职位,我可以使用Python subprocess.Popen()函数来运行Ruby的代码打印出来的值.

import subprocess
import sys

cmd = ["ruby", "/Users/smcho/Desktop/testit.rb"]
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
for line in iter(p.stdout.readline, ''):
    print line, 
    sys.stdout.flush() 
p.wait()
Run Code Online (Sandbox Code Playgroud)

我怎么能用C#做同样的事情?如何打印子进程打印出来的值?

c# subprocess interprocess

0
推荐指数
1
解决办法
2668
查看次数

Objective-C中的未知转义序列"\ 040"

我需要将"abc%20def%20xyz"替换为"abc\def\xyz".我用这个功能很好.

string2 =[string2 stringByReplacingOccurrencesOfString:@"%20" withString:@"\ "];
Run Code Online (Sandbox Code Playgroud)

但是,我得到警告说

Unknown escape sequence "\040".

这有什么问题,如何删除此警告?

string objective-c

0
推荐指数
1
解决办法
5630
查看次数

可可中的默认NSAutoreleasePool?

我询问了NSAutoreleasePool,并了解在这种情况下我需要显式分配自动释放池.

int main()
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    // Create an array
    NSArray *month = [NSArray arrayWithObjects:@ ... nill];

    [pool drain];
}
Run Code Online (Sandbox Code Playgroud)

在我的另一个问题中,我不需要发布NSArray,因为它将被自动释放.

- (NSArray*) getTodayArray
{

    ...

    NSArray *res = [NSArray arrayWithObjects: year, month, nil];

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

为了成为自动释放的对象,即使我没有创建任何NSAutorelease,也应该default在Cocoa中分配一些自动释放池.Xcode生成的主要功能非常简单.

int main(int argc, char *argv[])
{
    return NSApplicationMain(argc,  (const char **) argv);
}
Run Code Online (Sandbox Code Playgroud)

这是对的吗?如果是的话,何时以及如何分配?

cocoa objective-c autorelease

0
推荐指数
1
解决办法
388
查看次数

g ++中的"期望的类型说明符"错误

我有一个DD类

template<typename T>
class DD
: public IEnumerable<T>
{
    typedef IEnumerable<T> Super;
    typedef std::set<T*> Container;
Run Code Online (Sandbox Code Playgroud)

和方法

template<typename T>
bool DD<T>::Enumerator::Move()
{
    if(!mIt.get()) 
       mIt.reset(
          new Container::iterator( <-----
            mContainer.GetContainer().begin()
          )
       );
       ... 
}
Run Code Online (Sandbox Code Playgroud)

当我编写课程时,我得到了error: expected type-specifier.怎么了Container::iterator()

c++ g++

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

在产生和运行子进程时显示进度

我需要在生成和运行子进程时显示一些进度条或其他东西.我怎么能用python做到这一点?

import subprocess

cmd = ['python','wait.py']
p = subprocess.Popen(cmd, bufsize=1024,stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p.stdin.close()
outputmessage = p.stdout.read() #This will print the standard output from the spawned process
message = p.stderr.read()
Run Code Online (Sandbox Code Playgroud)

我可以使用这段代码生成子进程,但是我需要在每秒传递时打印出一些东西.

python subprocess progressdialog

0
推荐指数
1
解决办法
2238
查看次数

警告:使用 Homebrew 的 PATH 中的不安全世界可写目录 .../osx/bin,模式 040777

我正在使用homebrew来编译/安装 Mac 命令行工具。它使用 ruby​​ 来实现,每当我使用 时homebrew install SOMETHING,我都会收到warning: Insecure world writable dir .../osx/bin in PATH, mode 040777警告。bin目录的权限为777。为什么会出现这个警告,如何删除它们?

ruby installation homebrew

0
推荐指数
1
解决办法
1864
查看次数