在C ++中,你能创建一个对象作为arg来运行吗?(In C++, can you create an object as arg to function?)
在以下简单的两个类中
class B { private: int i; public: B( int p_i ) { i = p_i; }; } class C { private: B* b; public: C( B* p_b ) { b = p_b; }; }创建
B
作为C()
的参数是合法的吗?例如,是
C c = C( &B(5) );合法,创造
B
在飞行中?In the following simple two classes
class B { private: int i; public: B( int p_i ) { i = p_i; }; } class C { private: B* b; public: C( B* p_b ) { b = p_b; }; }is it legal to create
B
as an argument toC()
?for example, is
C c = C( &B(5) );legal, creating
B
on the fly?
原文:https://stackoverflow.com/questions/42338703
最满意答案
这个修改如何?
修改点:
- 通过分隔“标题”和“值”来检索每个数据。
- 创建一个用于将数据导入Spreadsheet的数组,并使用
setValues()
将其导入。修改的脚本:
function myFunction() { var sh = SpreadsheetApp.getActiveSpreadsheet(); var ss = sh.getActiveSheet(); var data = UrlFetchApp.fetch("https://www.binance.com/assetWithdraw/getAllAsset.html"); // Modified var out = JSON.parse(data.getContentText()); var title = []; for (var i in out[0]) { title.push(i); } var res = []; res.push(title); for (var i in out) { var values = []; for (var j in out[i]) { values.push(out[i][j]); } res.push(values); } ss.getRange(ss.getLastRow() + 1, 1, res.length, res[0].length).setValues(res); }
参考:
如果我误解了你的问题,请告诉我。 我想修改它。
编辑1:
为了从
out[0]
对象中检索关键字,我使用for (var i in out[0]) {
。 请看下面的例子。样品1:
结果var sample = [{key1: "value1", key2: "value2"}]; for (var i in sample[0]) { Logger.log("%s, %s", i, sample[0][i]) }
key1, value1 key2, value2
在此脚本中,
sample[0]
是{key1: "value1", key2: "value2"}
。for (var i in sample[0]) {
可以检索关键字key1
和key2
。 使用检索的键值,可以通过sample[0][i]
检索value1
和value2
。另一方面,请参阅下一个示例脚本。
样品2:
var sample = [{key1: "value1", key2: "value2"}]; for (var i = 0; i < sample[0].length; i++) { Logger.log("%s, %s", i, sample[0][i]) }
在这个脚本中,
sample[0].length
变得undefined
。 因为object.length
无法检索长度。 所以这个for循环不起作用。如果您想使用for循环来检索键和值,如示例2所示。请使用下一个示例脚本。
样品3:
结果var sample = [{key1: "value1", key2: "value2"}]; var keys = Object.keys(sample[0]); for (var i=0; i<keys.length; i++) { Logger.log("%s, %s", keys[i], sample[0][keys[i]]) }
key1, value1 key2, value2
在这个脚本中,可以通过
Object.keys()
来检索对象中的键。 使用这个,键和值被检索。参考:
编辑2:
function myFunction() { var sh = SpreadsheetApp.getActiveSpreadsheet(); var ss = sh.getActiveSheet(); var data = UrlFetchApp.fetch("https://www.binance.com/assetWithdraw/getAllAsset.html"); // Modified var out = JSON.parse(data.getContentText()); var title = []; for (var i in out[0]) { if (i == "assetCode" || i == "transactionFee") { title.push(i); } } var res = []; res.push(title); for (var i in out) { var values = []; for (var j in out[i]) { if (j == "assetCode" || j == "transactionFee") { values.push(out[i][j]); } } res.push(values); } ss.getRange(ss.getLastRow() + 1, 1, res.length, res[0].length).setValues(res); }
How about this modification?
Modification points :
- Retrieve each data by separating "title" and "values".
- Create an array for importing data to Spreadsheet and import it using
setValues()
.Modified script :
function myFunction() { var sh = SpreadsheetApp.getActiveSpreadsheet(); var ss = sh.getActiveSheet(); var data = UrlFetchApp.fetch("https://www.binance.com/assetWithdraw/getAllAsset.html"); // Modified var out = JSON.parse(data.getContentText()); var title = []; for (var i in out[0]) { title.push(i); } var res = []; res.push(title); for (var i in out) { var values = []; for (var j in out[i]) { values.push(out[i][j]); } res.push(values); } ss.getRange(ss.getLastRow() + 1, 1, res.length, res[0].length).setValues(res); }
Reference :
If I misunderstand your question, please tell me. I would like to modify it.
Edit 1 :
In order to retrieve keys from object which is
out[0]
, I usedfor (var i in out[0]) {
. Please see the following samples.Sample 1 :
Resultvar sample = [{key1: "value1", key2: "value2"}]; for (var i in sample[0]) { Logger.log("%s, %s", i, sample[0][i]) }
key1, value1 key2, value2
In this script,
sample[0]
is an object of{key1: "value1", key2: "value2"}
.for (var i in sample[0]) {
can retrieve keys which arekey1
andkey2
. Using retrieved keys,value1
andvalue2
can be retrieved bysample[0][i]
.On the other hand, please see the next sample script.
Sample 2 :
var sample = [{key1: "value1", key2: "value2"}]; for (var i = 0; i < sample[0].length; i++) { Logger.log("%s, %s", i, sample[0][i]) }
In this script,
sample[0].length
becomesundefined
. Becauseobject.length
cannot retrieve the length. So this for loop doesn't work.If you want to retrieve keys and values using for loop like the sample 2. Please use the next sample script.
Sample 3 :
Resultvar sample = [{key1: "value1", key2: "value2"}]; var keys = Object.keys(sample[0]); for (var i=0; i<keys.length; i++) { Logger.log("%s, %s", keys[i], sample[0][keys[i]]) }
key1, value1 key2, value2
In this script, keys from object can be retrieved by
Object.keys()
. Using this, keys and values are retrieved.Reference :
Edit 2 :
function myFunction() { var sh = SpreadsheetApp.getActiveSpreadsheet(); var ss = sh.getActiveSheet(); var data = UrlFetchApp.fetch("https://www.binance.com/assetWithdraw/getAllAsset.html"); // Modified var out = JSON.parse(data.getContentText()); var title = []; for (var i in out[0]) { if (i == "assetCode" || i == "transactionFee") { title.push(i); } } var res = []; res.push(title); for (var i in out) { var values = []; for (var j in out[i]) { if (j == "assetCode" || j == "transactionFee") { values.push(out[i][j]); } } res.push(values); } ss.getRange(ss.getLastRow() + 1, 1, res.length, res[0].length).setValues(res); }
相关问答
更多-
我已经在datatables论坛发布了这个问题,并回答了这个问题。 https://datatables.net/forums/discussion/46536/child-rows-show-extra-detailed-information-with-fixed-columns?new=1 https://datatables.net/download/compatibility 我已经解决了这个任务,就像这个代码。 var dataSet = []; // like json var column ...
-
列到行(Columns to rows)[2023-08-27]
对case使用聚合: SELECT (CASE WHEN pm.mortgagestatus = 10 then 'Received' WHEN pm.mortgagestatus = 4 then 'Passed' WHEN pm.mortgagestatu) = 5 then 'packaged' WHEN pm.mortgagestatus = 6 then 'Offered' END) as Mor ... -
SQL行为2列(SQL rows to 2 columns)[2022-04-19]
如果您提前知道列的列表,那么它应该像将两个列的每个组合并在一起一样简单: ;with Data as ( select 'A' as A, 'B' as B, 'C' as C, 'D' as D, 'E' as E, 'F' as F ) select A,B from Data union select C,D from Data union select E,F from Data 如果列列表是动态的,则需要动态SQL进行处理。 这是一个使用包含11列的测试表的完整工作示例: create ... -
这个修改如何? 修改点: 通过分隔“标题”和“值”来检索每个数据。 创建一个用于将数据导入Spreadsheet的数组,并使用setValues()将其导入。 修改的脚本: function myFunction() { var sh = SpreadsheetApp.getActiveSpreadsheet(); var ss = sh.getActiveSheet(); var data = UrlFetchApp.fetch("https://www.binance.com/assetWi ...
-
由于Firebase数据库数据是异步加载/同步的,因此更新范围时AngularJS不会监听它。 解决方案是让AngularJS在更新范围时了解: var ref = firebase.database().ref("users/MikeG1499"); ref.on('value',function(snapshot){ $timeout(function() { $scope.doesThisWork = snapshot.child("name").val(); }); }); 您也 ...
-
一些丑陋的RegEx来拯救 var regex = new Regex("To: ([A-z]+), ([A-z]+)"); var m = regex.Match(GetHtml()); var firstName = m.Groups[2].Value; var secondName = m.Groups[1].Value; 请注意,这是非常脆弱的,只适用于英文字母的方式。 编辑:根据请求细分正则表达式 "To: "是我们要查找的字符串必须从头开始的模式。 "([Az]+),"然后在逗 ...
-
我猜你忘了增加列索引 尝试下面 $row = 1; // 1-based index $col = 0; foreach ($this->data['total_by_city'] as $city_id => $total_city){ $city_name = ''; foreach ($this->data['total_by_legal_entities'] as $legal_entity_id => $total_legal_entity ...
-
根据ElastAlert文档 ,您可以使用include将警报限制为仅包含文档中的某些字段。 在你的情况下,它会是: include: ["@timestamp", "logLevel", "message"] According to the ElastAlert documentation, you can limit the alert to only containing certain fields from the document by using include. In your case ...
-
获取错误:4020:从无效的IP地址收到的信息(Getting Error : 4020 : Information received from an Invalid IP address)[2022-03-04]
登录到sagepay Simuator门户网站: https: //test.sagepay.com/Simulator/account.asp 点击角落里的红色“帐户”按钮, 在“此帐户的有效IP地址”部分添加您的IP地址。 Login to sagepay Simuator portal at https://test.sagepay.com/Simulator/account.asp click the red "Account" button in the corner, add your ip a ... -
我找到了。 我的错误假设是sms消息可以包含CrLf。 事实并非如此(至少对于uBlox SARA-G350而言)。 从模块接收的一些文本中的所有CrLf都被替换为Lf。 多亏了我可以知道,当下一个组合中的一个到达时,句末将结束:
OK ERROR > 最后一个是短信发送命令的提示符号。 I found it. My bad assumption was that sms message can contain CrLf wi ...