delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2005/05/26/04:24:26

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
From: Martin Ambuhl <mambuhl AT earthlink DOT net>
User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Problem in for loop (TC++ IDE)
References: <1117088627 DOT 434718 DOT 210400 AT g14g2000cwa DOT googlegroups DOT com>
In-Reply-To: <1117088627.434718.210400@g14g2000cwa.googlegroups.com>
Lines: 40
Message-ID: <4kfle.8039$M36.2408@newsread1.news.atl.earthlink.net>
Date: Thu, 26 May 2005 07:57:52 GMT
NNTP-Posting-Host: 165.247.30.13
X-Complaints-To: abuse AT earthlink DOT net
X-Trace: newsread1.news.atl.earthlink.net 1117094272 165.247.30.13 (Thu, 26 May 2005 00:57:52 PDT)
NNTP-Posting-Date: Thu, 26 May 2005 00:57:52 PDT
Organization: EarthLink Inc. -- http://www.EarthLink.net
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

aveo wrote with the strange subject line 'Problem in for loop (TC++ IDE)':

(If you are really using TC++, posting to a gcc newsgroup is pretty 
silly, and the IDE has nothing to do with errors in your program or with 
the compiler.)

> hi all,
> I came accross some problem in executing for loop.
> 
> void main()
   ^^^^ main returns an int in both C and C++
> {
>    for(;0;cout<<1)
>           cout<<2;
             ^^^^
     You are missing both a needed header and a namespace specifier (or 
using statement).  As it is, 'cout' is an undeclared variable in both 
C++ (and in C, where it must be an integral variable for the left shifts 
to be legal).

> }
> 
>          it gives me 21 as an output instade of blank output. Please
> let me know the reason behind it, as early as possible.

The legal C++ program below yields no output other than the terminating 
newline from the 'cout << endl;'.


#include <iostream>
using namespace std;

int main()
{
     for (; 0; cout << 1)
         cout << 2;
         cout << endl;
}


- Raw text -


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