Thread: Socket: send stringstream

  1. #1
    Registered User
    Join Date
    Nov 2007
    Location
    Hamburg, Germany
    Posts
    13

    Socket: send stringstream

    Hey everyone,

    i have a working socket connection and want to send a stringstream. But send() does not accept stringstreams.

    What would be the best way to send the stringstream?

    Thank you!

    Bye
    crisis

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Do you want to send the actual string collected in the stringstream? Use ss.str().c_str() to get a const char*, and send that.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User
    Join Date
    Nov 2007
    Location
    Hamburg, Germany
    Posts
    13
    thank you very much, CornedBee!

    i am always not sure when its smart to convert strings to chars because i dont have much experience yet

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    It's never smart, just sometimes necessary. The most common necessity is when you interact with a C API, like sockets.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Registered User
    Join Date
    Nov 2007
    Location
    Hamburg, Germany
    Posts
    13
    And there is no C++ library for Sockets, right? Just to make sure that its correct to use the C socket library in my C++ project...

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    There are a few socket libraries. My personal favourite is Asio. ACE is also good, but much more of a framework - takes longer to learn.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Socket Send Help
    By cloudy in forum Networking/Device Communication
    Replies: 2
    Last Post: 11-13-2007, 04:17 PM
  2. sending n no of char data uning send() function,
    By thebrighter in forum Windows Programming
    Replies: 1
    Last Post: 08-22-2007, 12:26 PM
  3. Socket or send() problem?
    By Achy in forum C Programming
    Replies: 5
    Last Post: 06-09-2006, 01:09 PM
  4. send zip file via socket
    By WaterNut in forum C Programming
    Replies: 11
    Last Post: 05-24-2005, 11:49 AM
  5. CString conversion for socket send()
    By WaterNut in forum C++ Programming
    Replies: 13
    Last Post: 04-27-2005, 04:55 PM