// JP opened flex table

Click to See Complete Forum and Search --> : simple Winsock question !!!


ARIX
March 2nd, 2004, 06:11 AM
Hi gurus !!!

I have a simple console app with the following code in it:

#include "stdafx.h"
#include "winsock2.h"
#include "iostream.h"
#include "stdio.h"

int main(int argc, char* argv[])
{
WSADATA wsa;
WSAStartup(1,&wsa);

SOCKET s = socket(AF_INET,SOCK_STREAM,IPPROTO_IP);
SOCKADDR_IN addr;
memset(&addr,0,sizeof(addr));

addr.sin_family = AF_INET;
addr.sin_port = htons(11000);
addr.sin_addr.s_addr = INADDR_ANY;

int res = bind(s,(sockaddr*)&addr, sizeof(sockaddr));
listen(s,3);
int size = sizeof(addr);
printf("Waiting for incoming connection...");
//cout << "Waiting for incoming connection...";

SOCKET sock = accept(s,(sockaddr*)&addr,&size);

return 0;
}


Now the question: Why it's when I use "cout <<" insetad of "printf()", the text appears only after connection accepted ?

Thanks in advance !!!

matze42
March 2nd, 2004, 06:17 AM
try

cout << ... << endl;

to flush the stream.

matze42
March 2nd, 2004, 06:25 AM
...

or
cout << ... << flush

if you dont want to have a line feed there.

ARIX
March 2nd, 2004, 06:57 AM
Thanks a lot !!!!!

matze42
March 2nd, 2004, 07:05 AM
You're welcome !:D

Andreas Masur
March 2nd, 2004, 10:51 AM
[Moved thread]

//JP added flex table