在gcc上执行此程序时,它对正数工作正常.但是当处理异常时,它不应该因负数而崩溃.但它给予核心转储.
#include <iostream>
using namespace std;
int main()
{
cout << "Enter a number: ";
double dX;
cin >> dX;
try
{
if (dX < 0.0)
throw "Can not take sqrt of negative number";
cout << "Going Good";
}
catch (char* strException)
{
cerr << "Error: " << strException << endl;
}
}
Run Code Online (Sandbox Code Playgroud) 我想从其父活动中调用片段方法.为此,我想要片段的对象.
父活动在framelayout中有片段,如下所示:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/bottom_buttons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
Run Code Online (Sandbox Code Playgroud)
这是获取片段对象的代码.
FragmentBottomButtons fragment = new FragmentBottomButtons();
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.bottom_buttons, fragment,"FragmentTag");
//ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
//ft.addToBackStack("");
ft.commit();
/*
getSupportFragmentManager()
.beginTransaction()
.add(R.id.bottom_buttons, new FragmentBottomButtons())
.commit();
*/
frag = (FragmentBottomButtons) getSupportFragmentManager().findFragmentByTag("FragmentTag");
//fragmentBottomButtons = (FrameLayout)findViewById(R.id.bottom_buttons);
if (frag == null){
Utility.displayToast("fragmnt is null");
}
Run Code Online (Sandbox Code Playgroud)
但它返回null.
谁可以帮我这个事?这有什么不对?
这是我从服务器获取数据的代码。
sampleApp.controller('OfferController', function ($scope, $state) {
var offersRef = firebase.database().ref('offers');
$scope.offers = [];
offersRef.on('value', function(snapshot) {
$scope.offers = snapshot.val();
//$state.go($state.current, {}, {reload: true});
});
});
Run Code Online (Sandbox Code Playgroud)
最初 $scope.offers = []; 是空的。这里正在被填满。$scope.offers = snapshot.val();
但是视图没有更新。如果我单击同一页面上的任何按钮或任何内容,或者返回并再次出现在同一页面上。它正在更新。
为什么不尽快更新数据可用?怎么修?
我有一个键列表和值列表。
['OpenInterest_x', 'Change in Open Interest x', 'LTP_x', 'NetChange_x', 'Volume_x', 'BidQty_x', 'BidPrice_x', 'OfferPrice_x', 'OfferQty_x', 'Strike Price', 'BidQty', 'BidPrice', 'OfferPrice', 'OfferQty', 'Volume', 'NetChange', 'LTP', 'OpenInterest', 'Change in Open Interest'
]
[
['150', '150', '1,070.00', '-928.90', '2', '450', '1,097.20', '1,314.15', '1,875', '4500.00', '375', '3.20', '10.25', '75', '-', '-', '-', '-', '-'],
['-', '-', '-', '-', '-', '150', '1,001.90', '1,056.15', '150', '4600.00', '75', '7.00', '17.80', '150', '4', '-7.55', '10.00', '1,350', '300']
]
Run Code Online (Sandbox Code Playgroud)
我有兴趣从两个字典中创建一个。请注意订购也很重要。这是我的预期输出。
{
{'OpenInterest_x': '150', ...},
{'OpenInterest_x': '-', ...},
}
Run Code Online (Sandbox Code Playgroud)
我无法在此处使用zip,因为它将为第一个键分配完整的第一列表。做这个的最好方式是什么?
我试图重载<<运算符以打印货币(用户定义的类型)
#include <iostream>
using namespace std;
struct Currency
{
int Dollar;
int Cents;
ostream& operator<< (ostream &out)
{
out << "(" << Dollar << ", " << Cents << ")";
return out;
}
};
template<typename T>
void DisplayValue(T tValue)
{
cout << tValue << endl;
}
int main() {
Currency c;
c.Dollar = 10;
c.Cents = 54;
DisplayValue(20); // <int>
DisplayValue("This is text"); // <const char*>
DisplayValue(20.4 * 3.14); // <double>
DisplayValue(c); // Works. compiler will be happy now.
return …Run Code Online (Sandbox Code Playgroud) 我总是读取初始化列表比构造函数体更适合初始化.我也知道静态变量可以在类外部进行初始化.
但我的问题是为什么我们不能在构造函数初始化列表中初始化静态变量,但我们可以在构造函数体中
class sample
{
static int i;
public:
sample (int ii=20) { i=ii;}
void show()
{
cout << i << endl;
}
};
int sample::i=12;
int main()
{
sample s;
s.show();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
工作正常并打印20.但我替换构造函数
sample (int ii=20): i(ii){}
Run Code Online (Sandbox Code Playgroud)
它给出了错误.为什么?
table_customers(customer_id, customer_name)
table_orders(customer_id, order_id, order_datetime)
Run Code Online (Sandbox Code Playgroud)
我想为last order date每个customer. 如果顾客没有下任何订单,请00-00-0000为她退货。
这是我的查询。
select C.customer_id , date(O.order_datetime)
from table_customers C
INNER JOIN table_orders O ON C.customer_id = O.customer_id
group by O.customer_id order by O.order_datetime desc limit 1;
Run Code Online (Sandbox Code Playgroud)
它仅返回最后一位客户的最后订单日期。
如何获取所有客户的最后订单日期?
我想获取所有客户的上次下单日期和手机号。这是我的查询。
SELECT c.customer_id, c.mobile, COALESCE( MAX( o.order_datetime ) , '0000-00-00 00:00:00' ) AS last_order_date
FROM table_orders AS o
RIGHT JOIN table_customers AS c ON o.customer_id = c.customer_id
GROUP BY c.customer_id
ORDER BY DATE( o.order_datetime )
Run Code Online (Sandbox Code Playgroud)
它工作正常。但是没有按 o.order_datetime 的 asc 顺序给我数据?
查询中的错误是什么?
这是我的代码段。
@Override
public void onDestroy() {
super.onDestroy();
disposableSingleObserver.dispose();
}
/**
* fetches json by making http calls
*/
private void fetchContacts() {
disposableSingleObserver = new DisposableSingleObserver<List<Contact>>() {
@Override
public void onSuccess(List<Contact> movies) {
//Toast.makeText(getActivity(), "Success", Toast.LENGTH_SHORT).show();
contactList.clear();
contactList.addAll(movies);
mAdapter.notifyDataSetChanged();
// Received all notes
}
@Override
public void onError(Throwable e) {
// Network error
}
};
// Fetching all movies
apiService.getContacts()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(disposableSingleObserver);
}
Run Code Online (Sandbox Code Playgroud)
我收到警告,未使用subscribeWith的结果。
解决此问题的正确方法是什么?
尝试使用require_fields装饰器装饰端点。这是实施。
import functools
from flask import request, jsonify
def requires_fields(fields):
required_fields = set(fields)
def wrapper(func):
@functools.wraps(func)
def decorated(*args, **kwargs):
current_fields = set(request.get_json().keys())
missing_fields = required_fields - current_fields
if missing_fields:
return jsonify({'error': 'missing fields', 'fields': list(missing_fields)}), 400 # Bad Request
resp = func(*args, **kwargs)
return resp
return wrapper
@app.route('/is_registered', methods=['POST'])
@requires_fields(['mobile'])
def is_registered():
_json = request.get_json()
keys = _json.keys()
customer = Customer()
registered = False
response = verify_required_params(['mobile'], keys)
if response:
return response
_mobile = _json['mobile']
validated = validate_mobile(_mobile)
cust, …Run Code Online (Sandbox Code Playgroud)