有此功能:
void func(const char *)
我想像这样使用它:
DWORD dWrd = 19;
func("I am " + dWrd + " years old!")
谢谢..
好的,我又有了一个与上述问题非常相关的功能,希望我不违反任何规则。
那如果我有一个接受将使用cout
打印并写入文件isinf fstream的参数的函数,我应该使用哪种数据类型?
void myFunc(char c)
吗?
void myFunc(const char c)
吗?
void myFunc(const char *c)
?
答案 0 :(得分:3)
您可以将所有内容转换为std::string
,然后使用c_str
获得const char*
func(("I am " + std::to_string(dWrd) + " years old!").c_str())
更加详细(并避免隐式转换)
func((std::string("I am ") + std::to_string(dWrd) + std::string(" years old!")).c_str())
当函数返回the temporary std::string
will be destroyed and the pointer is no longer valid时,请谨慎使用const char*
中的func
。
答案 1 :(得分:0)
使用protected void onPostExecute(String result) {
super.onPostExecute(result);
//text.setText(result);
try {
JSONObject obj = new JSONObject(result);
JSONArray airlinesArray = obj.getJSONArray("data");
for(int i = 0; i < airlinesArray.length(); i++){
JSONObject object = airlinesArray.getJSONObject(i);
String id=object.getString("id");
String rt=object.getString("route_type");
String flightname=object.getString("flight_name");
String fno=object.getString("flight_no");
String dd=object.getString("date_display");
HashMap<String, String> airliner = new HashMap<>();
airliner.put("id",id);
airliner.put("route_type",rt);
airliner.put("flight_name",flightname);
airliner.put("flight_no",fno);
airliner.put("date_display",dd);
ListAdapter adapter = new SimpleAdapter(
MainActivity.this, airlines,
R.layout.details, new String[]{"flight_name", "flight_no",
"date_display","time_display","display_route"}, new int[]{R.id.flightname,
R.id.flightnum, R.id.date,R.id.time,R.id.route});
lv.setAdapter(adapter);
:
std::ostringstream