11-24-2007
STL map
Hi there,
I am using the STL map and I print the map using:
map <string, float> ngram_token_index ;
map <string, float>::iterator map_iter ;
//read the map
...
// print the map
for ( map_iter = ngram_token_index.begin() ; map_iter != ngram_token_index.end() ; map_iter++ )
cout << map_iter->first << " => " << map_iter->second << endl;
While this works, I want to copy the value in map_iter->first to a string variable.
The code
char str[1024] ;
strcpy(str, map_iter->first) ;
gives the following error:
error: cannot convert 'const std::basic_string<char, std::char_traits<char>, std::allocator<char> >' to 'const char*' for argument '2' to 'char* strcpy(char*, const char*)'
I am new to STL. Any help would be greatly appreciated.
Thanks,
J.
7 More Discussions You Might Find Interesting
1. Programming
Help me please with STL source code that works on Windows
I've found on Inet STL MRU Cache (it compiles fine with Studio 2008), but when trying to build it with Kdevelop (g++ is the compiler) I've got a series of error. One of them I've placed in the source code. If it's important I can post here... (0 Replies)
Discussion started by: Orlando_ua
0 Replies
2. UNIX for Dummies Questions & Answers
Hello,
I'm using RHEL 5.3, I need to compile C++ code and I'd like to know which rpm contains the STL library.
Thanks:) (3 Replies)
Discussion started by: pppswing
3 Replies
3. Programming
class tst
{
public:
tst() {
cout<<"ctor tst()\n";
}
tst(const tst& ob) {
cout<<"cp ctor tst()\n";
}
~tst()
{
cout<<"dtor tst()\n";
}
};
map<string,tst> mp;
int main(void)
{
mp;
//mp=tst();
} (1 Reply)
Discussion started by: johnbach
1 Replies
4. Programming
hi all
i have a tree structure:
root --- node 1 to node 10
in each node --- sub node 1 to sub node 10
in each sub node --- leaf node 1 to leaf node 10
i have to print this in following fashion:
root ---- n1 ---- sn1 ---- l1, l2, l3, ....., l10
n1 ---- sn2 ---- l1, l2, l3,... (2 Replies)
Discussion started by: vidyaj
2 Replies
5. Programming
hi all,
i need c++ code to print a binary or non binary tree using stl map....
please help me to find the same.......... (1 Reply)
Discussion started by: vidyaj
1 Replies
6. Programming
Hi, guys.
I am working on a project right now. But when I debug my code, I can't see the values in stl container, e.g vector, map. Can anyone help me, please. I am really frustrated:wall:. I am using code::blocks IDE, by the way. Thanks in advance...... (0 Replies)
Discussion started by: tefino
0 Replies
7. Programming
Hi all,
I pass to the transform algorithm two vectors, and the suma function.
#include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>
using namespace std;
class Duo{
public:
int one;
int two;
};
Duo suma(Duo first, Duo last){
Duo ret;
... (1 Reply)
Discussion started by: santiagorf
1 Replies
LEARN ABOUT MOJAVE
ypmatch
ypmatch(1) User Commands ypmatch(1)
NAME
ypmatch - print the value of one or more keys from a NIS map
SYNOPSIS
ypmatch [-k] [-t] [-d domain] key [key...] mname
ypmatch -x
DESCRIPTION
ypmatch prints the values associated with one or more keys from the NIS's name services map specified by mname, which may be either a map
name or a map nickname.
Multiple keys can be specified; all keys will be searched for in the same map. The keys must be the same case and length. No pattern match-
ing is available. If a key is not matched, a diagnostic message is produced.
OPTIONS
The following options are supported:
-k Before printing the value of a key, print the key itself, followed by a colon (:).
-t Inhibit map nickname translation.
-d domain Specify a domain other than the default domain.
-x Display the map nickname table. This lists the nicknames the command knows of, and indicates the map name associated with
each nickname.
OPERANDS
The following operand is supported:
mname The NIS's name services map
EXIT STATUS
The following exit values are returned:
0 Successful operation.
1 An error occurred.
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|Availability |SUNWnisu |
+-----------------------------+-----------------------------+
SEE ALSO
ypcat(1), ypfiles(4), attributes(5)
NOTES
ypmatch will fail with an RPC error message on yp operation if enough file descriptors are not available. The number of file descriptors
should be increased if this occurs.
SunOS 5.10 22 Aug 1997 ypmatch(1)