Article View: att.lang.c++
Article #97Re: This bit of code won't compile
From: Paul S Usowicz
Date: Wed, 31 May 2000 00:00
Date: Wed, 31 May 2000 00:00
62 lines
2795 bytes
2795 bytes
There are a number of points to raise here.
1) This is, I presume, only part of the full program. Your errors mention
line numbers 24 and 25. I assume the previous lines are #includes (probably
iostream.h and iomanip.h), a main() function and 2 global declerations for
hours and minutes.
2) Assuming the above your problem is exactly the opposite to what the
error is telling you. The real problem is that the line before is ended
with a semicolon. So your real problem is ';' before '<<'.
The following code compiles
void display()
{
cout << hours << ":" // hours and colon
<< setfill('0') // fill character is '0'
<< setw(2) << minutes; // minutes is 2 chars wide
}
When the code is preprocessed it removes all comments and whitespace so it
will look more like (padded for readability):
cout << hours << ":" << setfill('0') << setw(2) << minutes;
The semicolon is used to delineate instructions so you originally had an
instruction of:
<< setfill('0');
This is, of course, no use as you have no left hand object to stream into.
Hope this helps,
Cheers for now,
Paul S Usowicz
psu@psu.uk.com
Sidey <richardmosquera@hotmail.com> wrote in message
news:8g1jac$6u3$1@plutonium.btinternet.com...
>
> This is a listing from C++: An interactive course. This bit of code is
an
> exact copy of the listing but it won't compile.
> I'm using MS Visual C++ 6 introductary edition.
>
> thanx in advance,
> Richard
>
>
> void display()
> {
> cout << hours << ":"; // hours and colon
> << setfill('0'); // fill character is
'0'
> << setw(2) << minutes; // minutes is 2 chars wide
> }
>
> E:\Cpp\Projects\Interactive Course\Listing2_4\Source\Main.cpp(24) : error
> C2143: syntax error : missing ';' before '<<'
> E:\Cpp\Projects\Interactive Course\Listing2_4\Source\Main.cpp(25) : error
> C2143: syntax error : missing ';' before '<<'
>
>
>
>
Technical Details
Message-ID:
<I69Z4.32$QA4.6289@news.enterprise.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<8g1jac$6u3$1@plutonium.btinternet.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10d4ba,11f12a1c47eb93ac,start X-Google-Attributes: gid10d4ba,public From: "Paul S Usowicz" <newsgroup@psu.uk.com> Subject: Re: This bit of code won't compile Date: 2000/05/31 Message-ID: <I69Z4.32$QA4.6289@news.enterprise.net> X-Deja-AN: 629468315 References: <8g1jac$6u3$1@plutonium.btinternet.com> X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.207 X-Complaints-To: news@enterprise.net X-Trace: news.enterprise.net 959782440 212.161.115.83 (Wed, 31 May 2000 15:14:00 BST) Organization: Enterprise PLC X-MSMail-Priority: Normal NNTP-Posting-Date: Wed, 31 May 2000 15:14:00 BST Newsgroups: att.lang.c++