eidheim / Simple-Web-Server

A very simple, fast, multithreaded, platform independent HTTP and HTTPS server and client library implemented using C++11 and Boost.Asio. Created to be an easy way to make REST resources available from C++ applications.
MIT License
2.62k stars 758 forks source link

cout is not working in lambda function of a route #81

Closed ghost closed 8 years ago

ghost commented 8 years ago

the code inside a handler works as usual, except 'cout', for example:

server.resource["^/$"]["GET"] = [](................){
  cout << "abc";
};

it doesn't print out anything

void handle_get_root(.........................){
  cout << "xyz";
}

server.resource["^/$"]["GET"] = handle_get_root;

doesn't print out 'xyz' too

ghost commented 8 years ago

tks god, i found the answer: http://stackoverflow.com/questions/14858262/stdcout-wont-print

i need to call cout.flush()

but i still don't know why i have to call 'flush'.

most of the time nobody needs to call 'flush'

eidheim commented 8 years ago

There are no guarantees that a flush is called when you use std::cout, unless using std::endl, std::flush, or when a program exits. In the case above, I would simply write cout << "abs" << endl; when using std::cout for testing purposes.

ghost commented 8 years ago

ah yeah, endl works