?
Solved

c++ pointer to string question

Posted on 2012-09-06
2
Medium Priority
?
476 Views
Last Modified: 2012-09-06
zmq::message_t topic;
 std::string secID =  md.get_securityID() ;   // value is "123"
 std::cout << &secID << std::endl;
 memcpy( topic.data() , &secID, 20 );
 m_socket->send( topic,  ZMQ_SNDMORE );

sends passes encoded text possible a memory location while:


 zmq::message_t topic;
 std::string secID =  md.get_securityID() ;  
 std::cout << &secID << std::endl;
 memcpy( topic.data() , "123", 3 );
 m_socket->send( topic,  ZMQ_SNDMORE );


The hard-coded string is correctly passed as "123" in the topic message.

memcpy  arguments are  ( pointer, pointer, length)

How do I pass the value of md.get_securityID not the address in the topic message?
0
Comment
Question by:mcgilljd
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 2000 total points
ID: 38373940
You'd use 'string::c_str()', e.g.

memcpy( topic.data() , secID.c_str(), secID.legth() );

Open in new window

0
 

Author Closing Comment

by:mcgilljd
ID: 38373972
Works great!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question