delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/12/27/13:18:06

X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f
From: "Cody" <cody1 AT ktsnet DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: istream::get() problems
Lines: 32
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4133.2400
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400
X-Original-NNTP-Posting-Host: kx-nachtx-ppp029.ktsnet.com
Message-ID: <3c2b6707@leia.ktsnet.com>
Date: Thu, 27 Dec 2001 12:13:39 -0600
NNTP-Posting-Host: 216.60.177.225
X-Complaints-To: abuse AT swbell DOT net
X-Trace: nnrp2.sbc.net 1009476780 216.60.177.225 (Thu, 27 Dec 2001 12:13:00 CST)
NNTP-Posting-Date: Thu, 27 Dec 2001 12:13:00 CST
Organization: SBC Internet Services
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

I'm having difficulty understanding why the following gives an infinite loop
on djgpp 3.0.2 but not on prev. versions nor on TC++ 3.0:

#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;

int get_key();//problematic function

int main() {
   cout<<get_key()<<endl;
   return EXIT_SUCCESS;
}

int get_key() {
ifstream input("con");
//of course "con" is non-standard, but it's still a "file", so there should
be no problem
return input.get();
//get() creates infinite loop (well, not inf. loop, but it waits until I
press EOF [Cntr+Z]).
//get() is supposed to return next char in the istream after '\n is pressed,
not return
//next key only after EOF has been pressed.
//What am I doing wrong?

--
__________________________________
Microsoft spel chekar vor sail, worgs grate!


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019