获取引用携带的内容
我有一个对字符串对象的引用,如何从中获取数据。这是我的示例:
string key = "key1";
gpointer somepointer;
GHashTable* myTable;
g_hash_table_insert(myTable,&key1,somepointer);
GList *keysList = g_hash_table_get_keys(myTable);// here i got keys previously set
keysList = g_list_first(keysList);
string recentKey = (keysList->data);
数据指的是字符串的引用。我如何从参考中检索数据
I have a reference to a string object how can i get the data from it. Here is my sample:
string key = "key1";
gpointer somepointer;
GHashTable* myTable;
g_hash_table_insert(myTable,&key1,somepointer);
GList *keysList = g_hash_table_get_keys(myTable);// here i got keys previously set
keysList = g_list_first(keysList);
string recentKey = (keysList->data);
data refers to reference of a string. How can i retrieve the data from the reference
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果
keysList->data
是gpointer
(void*
),我猜想有些像需要以下内容:
希望这有帮助
If
keysList->data
isgpointer
(void*
), I guess some cast like thefollowing is needed:
Hope this helps
如果 data 是对字符串的引用,那么,
keysList->data 返回该字符串。
If data is reference to a string then,
keysList->data returns the string.
“我如何从参考文献中检索数据?”是什么意思?你有尝试过这样做吗?
std::string
中的唯一数据是字符串长度和有效负载char*
数组。keysList->data.length()
将访问长度,而keysList->data.c_str()
将访问char*
数组。您的最后一个语句是从引用中获取数据:
此语句创建字符串的完整副本。因为它是副本,所以对
recentKey
的任何修改都不会显示在keysList->data
中。这是好事还是坏事取决于您的意图。What do you mean by "How can i retrieve the data from the reference?" Have you tried just doing it?
The only data in an
std::string
are the string length and the payloadchar*
array.keysList->data.length()
will access the length whilekeysList->data.c_str()
will access thechar*
array.Your last statement is getting the data from the reference:
This statement creates a full copy of the string. Because it is a copy, any modifications to
recentKey
will not show up inkeysList->data
. Whether that is a good or bad thing depends on your intent.