当我尝试除以0时,下面的代码没有捕获异常.我是否需要抛出异常,或者计算机是否在运行时自动抛出一个异常?
int i = 0;
cin >> i; // what if someone enters zero?
try {
i = 5/i;
}
catch (std::logic_error e) {
cerr << e.what();
}
Run Code Online (Sandbox Code Playgroud) 为什么下面的线不起作用?
#include <iostream>
std::ostream& operator <<( std::ostream& os, const char *c)
{
os << c; // why does this line doesn't work?
return os;
}
int main()
{
const char *c = "Hi";
std::cout << c;
}
Run Code Online (Sandbox Code Playgroud)