Re: GHashTable insertion problems (string literals, c_str(), etc.)



edwardt wrote:

No particular reason - its just when I searched "Vector" and "HashTable" in
Google, glib / GTK+ came up first.

Then glib is not the right tool. Just use the standard STL types vector and hashtable.

I tried using STL for insertions as well, but I came up with the same
c_str() "addressing" problem. The issue seems to be that when I insert with
a .c_str() into the hash table (both gtk's and STL's) it records the
address(?).
It seems like if I pass in a "string literal", it works. Is
there some way, glib can convert variables into string literals?
I do notice there is a "g_string(x)" macro but I'm not sure how to use it.


This is a basic C++ programming issue, so you would probably be better off looking for answers elsewhere, but if I understand you correcly you should probably just do something like:

vector<string> v;
string s;

s = "foo";
v.push_back(s);
s = "bar";
v.push_back(s);

--
Christer




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]