473,406 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Map iterator to string

I'm looking for a good method to convert a map::iterator to a
std::string. I've tried googling for a while, but haven't come up with
much. Perhaps I'm kludging things here. Either way any advice would
be greatly appreciated.

Oct 20 '08 #1
5 4556
Micheal Smith wrote:
I'm looking for a good method to convert a map::iterator to a
std::string. I've tried googling for a while, but haven't come up with
much. Perhaps I'm kludging things here. Either way any advice would be
greatly appreciated.
What are you hoping to get from the conversion?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Oct 20 '08 #2
On 2008-10-20 13:43:58 -0500, Victor Bazarov <v.********@comAcast.netsaid:
Micheal Smith wrote:
>I'm looking for a good method to convert a map::iterator to a
std::string. I've tried googling for a while, but haven't come up with
much. Perhaps I'm kludging things here. Either way any advice would
be greatly appreciated.

What are you hoping to get from the conversion?

V
I have a member function that searches a map for a key. The value tied
to the given key should be a std::string. It just seemed like a better
idea to return the original std::string, than simply an iterator.

Oct 20 '08 #3
Micheal Smith wrote:
On 2008-10-20 13:43:58 -0500, Victor Bazarov <v.********@comAcast.net>
said:
>Micheal Smith wrote:
>>I'm looking for a good method to convert a map::iterator to a
std::string. I've tried googling for a while, but haven't come up
with much. Perhaps I'm kludging things here. Either way any advice
would be greatly appreciated.

What are you hoping to get from the conversion?

V

I have a member function that searches a map for a key. The value tied
to the given key should be a std::string. It just seemed like a better
idea to return the original std::string, than simply an iterator.
What's wrong with using iterator->second?

--
Ian Collins
Oct 20 '08 #4
Micheal Smith wrote:
On 2008-10-20 13:43:58 -0500, Victor Bazarov <v.********@comAcast.net>
said:
>Micheal Smith wrote:
>>I'm looking for a good method to convert a map::iterator to a
std::string. I've tried googling for a while, but haven't come up
with much. Perhaps I'm kludging things here. Either way any advice
would be greatly appreciated.

What are you hoping to get from the conversion?

V

I have a member function that searches a map for a key. The value tied
to the given key should be a std::string. It just seemed like a better
idea to return the original std::string, than simply an iterator.
Your original post is very poorly written. You are asking in your
original post how to *convert* a map::iterator (what kind of map?) into
a std::string. What does that even mean? Are you trying to generate a
string from the value of the iterator? Are you trying to cast the
iterator into a string? What?

Seemingly what you have is a std::map<something, std::string>, and you
have an iterator pointing to an element of this map, and you want to
dereference the string at that position in the map (which happens with
"yourIterator->second", which is probably the answer you are looking for).

You should be much more specific when you ask such questions.
Oct 20 '08 #5
Seemingly what you have is a std::map<something, std::string>, and you
have an iterator pointing to an element of this map, and you want to
dereference the string at that position in the map (which happens with
"yourIterator->second", which is probably the answer you are looking for).
or:
my_iterator->first

for std::map<std::string, anything>;

Oct 22 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
by: Michael Klatt | last post by:
I am trying to write an iterator for a std::set that allows the iterator target to be modified. Here is some relvant code: template <class Set> // Set is an instance of std::set<> class...
29
by: Hagen | last post by:
Hello, in a recent thread "speed of vector vs array" I read about the problem of the slow acces by addressing vector elements by indexing, unfortunately I see no workaround in my case. My...
3
by: Brett Robichaud | last post by:
What is the correct way to allocate a string:iterator using a char* buffer? In Visual C++ 7.1 the following works fine (where pBuf is a char*): std::string::iterator start = pBuf; But under...
0
by: eric | last post by:
Hi, I would like to build the inParams SQLJ sample procedure from the Development Center. if I declare a #sql public iterator SpIterat, the Development Center complains this should be in a...
4
by: KL | last post by:
Well, I got through those other hurdles, but now I am stuck with trying to get an iterator to work. I am having a problem with trying to iterate through the STL list container that I set up. I...
3
by: chriscorbell | last post by:
I'm curious about what appears to be a restriction on using an STL container inside a user-defined template, esp. using an iterator to such a container. It's not clear to me if this is a general...
15
by: vivekian | last post by:
Hi, I have this following class class nodeInfo ; class childInfo { public: int relativeMeshId ;
1
by: Saile | last post by:
I want to give an array the values from the specific multimap's key's values. multimap<string,int> mymultimap; multimap<string,int>::iterator it;...
3
by: JurgenvonOerthel | last post by:
I want to replace one element in a list<stringby a list<stringand I need to obtain an iterator to the first element in the inserted list. In code: void...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.