0
string hello;
        cin>>hello;
        sprintf(buf, "This server has been contacted time%s\n", hello);

I'm making a simple client-server program. I just want to know how do I get to print out the hello string inside the sprintf() >.< soz might be a very dumb question....

The error i keep getting is "can't pass objects of non-POD type"

3
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by BradenMurphy
0

You have to get there a const char * , which is what the c_str() function gives you (i.e. hello.c_str()).

0

How about doing something like

string msg = "This server has been contacted time";
msg += hello;
msg += "\n";

Then later, when you absolutely need a char array to call send(), do this send( fd, msg.c_str(), msg.length(), 0 );

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.