1748089 Members
4937 Online
108758 Solutions
New Discussion юеВ

Re: C++ STL

 
Tnameh
Occasional Advisor

C++ STL

I want to implement this in C++.I will have one file in which i will define Key and value.

What i want to do is that i wll read file once store all the value in
data structure. And wll do search for that particular key and it should
return me value of that particular Key. Key and Value are string and Key
will always be unique.

Can anyone suggest me better way of doing it Using C++,STL

For Example

file contents are

hello1:def
hello2:cef
Hello3:gef
Hello4:cef
Hello5:cef.

Suppose i search for hello2 it should return me cef.Hope i am clear.
3 REPLIES 3
Peter Godron
Honored Contributor

Re: C++ STL

Hi,
something along the lines of the attached code. Test comiled with gcc
Parameters:
1. Input filename
2. Key to look for

e.g. ./a data.lis Hello4


If you happy with this solution please award points.
Tnameh
Occasional Advisor

Re: C++ STL

Well, i could not find the attached file.
Dennis Handly
Acclaimed Contributor

Re: C++ STL

I don't see Peter's example so I wrote my own. Most of the source is fluff to get the file and read it. The only important thing is the STL "insert": m_string[key] = value;
And the find: mss_iter itr = m_string.find(argv[2]);