cin >> pour sortir d'un while
Bonjour,
Je souhaite sortir d'une boucle d'ecoute de serveur grace a l'entree de "Y" au clavier.
J'avais en premier ecris :
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| char* stopServer = "";
while(stopServer != "Y") {
cout<<"Waiting for a socket connexion"<<endl;
queryStr = getQueryFromSocket();
answerStr = sendAndRecieve(queryStr);
sendAnswerToSocket("Server reply: xml string");
cout<<"Close server: Y/N"<<endl;
cin>>stopServer;
} |
Et le programme me demandais jamais mon avis, et sortais jamais :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| $./a.out
stub: send to motisRequest read from motisReply
check point fifoExist
Test if FIFO motisRequest.fifo is already there ...
Open FIFO motisRequest.fifo for writing and wait for the other side ...
OK, here we go ...
Open FIFO motisReply.fifo for reading and wait for the other side ...
...initialized
Server initialized
Waiting for a socket connexion
Y
Socket connected
Query String: 29 3 2007 10 59 29 3 2007 10 59 D 0 8004338 %% 16 8000002
send: 29 3 2007 10 59 29 3 2007 10 59 D 0 8004338 %% 16 8000002
send request...done
waiting for reply...strange: nothing to read
stub got:
Answer from server: Server reply: xml string
Close server: Y/N
Waiting for a socket connexion
y
^C |
Puis j'ai chercher, et j'ai lu : http://jlecomte.ifrance.com/c++/c++-...output-fr.html et particulierement le paragraphe [15.2]Pourquoi mon programme part-il en boucle infinie quand quelqu'un entre un caractère invalide?
Du coup, j'ai ecris ca :
Code:
1 2 3 4 5 6 7 8 9 10 11
| while((cin>>stopServer) && (stopServer != "Y")) {
cout<<"Waiting for a socket connexion"<<endl;
queryStr = getQueryFromSocket();
answerStr = sendAndRecieve(queryStr);
sendAnswerToSocket("Server reply: xml string");
cout<<"Close server: Y/N"<<endl;
} |
Mais la il sort tout le temps...
Code:
1 2 3 4 5 6 7 8 9 10
| $./a.out
stub: send to motisRequest read from motisReply
check point fifoExist
Test if FIFO motisRequest.fifo is already there ...
Open FIFO motisRequest.fifo for writing and wait for the other side ...
OK, here we go ...
Open FIFO motisReply.fifo for reading and wait for the other side ...
...initialized
Server initialized
stub: request shutdown |
Je suis a la recherche d"une solution ! Merci d'avance
PS : le clavier qwerty explique l'absence d'accent dans mon message.