PDA

View Full Version : C++ help


lashunda
09-20-2003, 09:28 PM
I KEEP GETTING THE FOLLOWING ERROR

error C2146: syntax error : missing ';' before identifier 'cout'
error C2059: syntax error : ')'
error C2297: '<<' : illegal, right operand has type 'char [18]'
warning C4552: '>>' : operator has no effect; expected operator with side-effect
Error executing cl.exe.

ON THESE STATEMENTS

cout << "\nPlease try again...\n" << endl;
cout << "How much is " << a << "* " << b << "? ";
cin >> answer2;
cout << "\n";

EscapeCharacter
09-20-2003, 10:31 PM
did you include iostream?

Jeb.
09-21-2003, 01:25 AM
Originally posted by lashunda
error C2146: syntax error : missing ';' before identifier 'cout'

After you check for iostream, make sure you've closed the statement a line or two before the ones you posted. Always start with the first reported error - most times the following errors are caused by the first.

stuka
09-22-2003, 11:13 AM
And, of course, make sure that you either change your cout and cin to std::cout and std::cin, or put using std::cin;
using std::cout; just below the include of <iostream>.

n00b++
09-22-2003, 06:24 PM
do you have:

#include<iostream>
using namespace std;

what compiler are you using?

stuka
09-23-2003, 11:33 AM
Originally posted by n00b++
do you have:

#include<iostream>
using namespace std; PLEASE! Get out of the habit of using namespace std; now! Don't recommend it to your friends! Treat it like Gigli, or Ishtar! Run far, far from it! It will save your life some day!

n00b++
09-23-2003, 01:13 PM
well im not the C++ guru ... ive only been at it for a few weeks now, why is it a bad idea to use it?

stuka
09-23-2003, 01:21 PM
http://www.justlinux.com/forum/showthread.php?s=&threadid=108980&highlight=namespace+std We had a lengthy discussion on the subject on another board. This is the text of that, including the reasons why you shouldn't do it.

CrazyMeat
09-24-2003, 09:31 PM
Originally posted by Stuka
http://www.justlinux.com/forum/showthread.php?s=&threadid=108980&highlight=namespace+std We had a lengthy discussion on the subject on another board. This is the text of that, including the reasons why you shouldn't do it.

I totally agree if you put using namespace std then you are just cluttering up global space. This definately shouldn't be done. Instead use stuff like:


using std::cout;
using std::cin;


This is much better then including all of the namespace into your program which can clutter it up.

kryptech.net
10-01-2003, 09:37 PM
if all else fails restart the compiler Ive been up at 4:30 in the morning pulling out my hair and all I had to do was restart the compiler

kryptech.net
10-01-2003, 09:39 PM
ok this should work. be sure to use std::cout NOT JUST cout

Jamaican
10-01-2003, 10:35 PM
My friend it depends on your program size and what your program contains. Stucka said, PLEASE! Get out of the habit of using namespace std; now! Don't recommend it to your friends! Treat it like Gigli, or Ishtar! Run far, far from it! It will save your life some day!
But his advise is true to some extent. I personally use it and have no problems with it at all. Their main argument is that it clogs up global space. however, that is their error: if they want to put all their vaiables in global space, what the hell do they expect to happen?
and another thing: put it this way, even Bjarne Stroustrup who made C++ uses namespace std in his programs (find chapters of his books at his web site, http://www.research.att.com/~bs/homepage.html)
I understand what they are trying to prevent, but as I said, its their fault it happened in the first place.

this is my advise to you: don't put all your variables in global space.

Jamaican
10-01-2003, 10:45 PM
Bjarne is promoting good programming style, which he feels, a lot of C++ programmers lack. you'll see and read all about it at his site.

um, his site doesn't look all that hot. but if you have a lot of work to do, you have no time to make a site look good when you have other pressing matters to attend. all you'd care about is that it has all the information you want to put forward.