Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Easy for you guru's :)

Status
Not open for further replies.

quanta

Technical User
May 18, 2002
2
NZ
Hey guys,

As of 74 minutes ago I started learning C++. I woke up this morning, made a coffee, and since then I've written two programs. One that says "I'm a C++ Programmer" and the other adds 8 and 5 together. I had no intention of learning C++ but now I've started I can't stop.

Anyway I have a question - and being the newbie I am I'm sure it won't strain your brains :) I am just learning about "cout" and "endl" and have been told to write a very simple script that puts some things on the sreen. However, I am faced with two errors when I try and compile it which I cannot work out! (I am using Microsoft Visual C++ to compile it - Ill just post the 2 lines that are causing my grief.

1. cout << &quot;Here's a fraction:t\&quot; << (float) 5/8 << endl;

The error for this line is -
C:\hello\leet.cpp(11) : error C2001: newline in constant

2. cout << &quot;And a VERY big number:\t\t&quot; << (double) 7000 * 7000 << endl;

And the error for this line is -
C:\hello\leet.cpp(12) : error C2146: syntax error : missing ';' before identifier 'cout'

I just want to know why they are errors and what should be done to fix them - I want to _understand_ why they are errors.

Anyway I'm sure you are all busy and probably find a question like this &quot;boring&quot; and I could understand if you tell me to go work it out for myself! But I thought I'd ask anyway :)

Thanks heaps
Quanta
 
The lines of code you posted are correct. The errors actually refer to lines preceding the line on which they are caught.

The &quot;newline in constant&quot; error means that somewhere (probably right before the line you posted), you started a string literal by using a &quot; (quote), but you never finished it with another &quot;, or else you have a newline (i.e. an &quot;enter&quot;) before you do.

The one about the semicolon says that you forgot a semicolon on the line before.

As to why they're errors, you simply can't have a newline in a character literal, and every statement has to end with a semicolon.
 
I am guessing that the second line is below the first so to get rid of both those errors change the &quot;t\&quot; to &quot;\t&quot;...
 
Thanks heaps guys, you have explained alot. I will try correcting the errors now.

Appreciate your quick replies.

Quanta
Patterns of organic energy.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top