c++ pointer to string question

Posted on 2012-09-06
Last Modified: 2012-09-06
zmq::message_t topic;
 std::string secID =  md.get_securityID() ;   // value is "123"
 std::cout << &secID << std::endl;
 memcpy( , &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( , "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?
Question by:mcgilljd
    LVL 86

    Accepted Solution

    You'd use 'string::c_str()', e.g.

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

    Open in new window


    Author Closing Comment

    Works great!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
    Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
    The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
    The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now