PDA

View Full Version : whats wrong with this program?



luposolo
February 7th, 2010, 11:30 PM
What, if anything, is wrong with the following cout statement?


cout >> "My name is Maria; << endl

What, if anything, is wrong with the following program?


#include <iosteam main(){ cout << "Is there something
wrong " << endl << endl cout << "with this program"?; }

thank you and god bless

LKjell
February 8th, 2010, 12:11 AM
We are not suppose to do your home work. So put that in a compiler and read the error message.

luposolo
February 8th, 2010, 12:25 AM
i just need help with this now

#include <iosteam main(){ cout << "Is there something
wrong " << endl << endl cout << "with this program"?; }

LKjell
February 8th, 2010, 12:29 AM
#include <iosteam
main(){
cout << "Is there something wrong " << endl << endl
cout << "with this program"?; }

Same as your code. compile that should make it easier to debug.

MadCow108
February 8th, 2010, 12:30 AM
wow you win the prize for most syntax errors in one line :/

its iostream not iosteam
the include is unterminated
main has no return type (it needs to int)
there are various missing semicolons or too many semicolons in the wrong places
and finally the actual return is missing from the main function.

lisati
February 8th, 2010, 12:32 AM
cout >> "My name is Maria; << endl

Huh? Channelling stuff FROM cout to a string literal? :confused:

Ravenshade
February 8th, 2010, 12:34 AM
Since I'm learning C++ let me have a shot at doing your homework. If you don't want to benefit from it, I want to ^_^

#include <iostream>

int main()
{
cout << "Is there something wrong " << endl << endl;
cout << "with this program?";
}


I personally don't use endl, can't see the purpose when \n does the same job really. (Someone tell me I'm wrong)

LKjell
February 8th, 2010, 12:39 AM
Most logic sense is that endl is map to \r\n on windows.

MadCow108
February 8th, 2010, 12:41 AM
I personally don't use endl, can't see the purpose when \n does the same job really. (Someone tell me I'm wrong)

\n is plattform dependent
also endl serves another purpose, it flushes the stream.
if you need neither "benefits" \n is fine.

Ravenshade
February 8th, 2010, 01:03 AM
but \n works on both windows and linux. Does it not work on mac?

(At least I used to code in java with \n on windows vista and windows 7)

LKjell
February 8th, 2010, 01:11 AM
but \n works on both windows and linux. Does it not work on mac?

(At least I used to code in java with \n on windows vista and windows 7)

Java is special... Actually you should use %n in java.

Ravenshade
February 8th, 2010, 01:30 AM
Odd my lecturer always taught us using \n... No matter, as long as you only mean platform in terms of language.

I'm trying to stick to C++ since most people say it's the language that will teach you pretty much the basics and make it easier to crack other languages open like a walnut ^_^

wmcbrine
February 8th, 2010, 01:39 AM
'\n' is universal, IF the thing you're writing to was opened in text mode.

As far as I can tell, the difference between '\n' and endl is that endl flushes the output buffer.

Ravenshade
February 8th, 2010, 01:41 AM
That's logical. Though just so I understand you a little better.

Is that opening in a text editor, or expecting text output? Since I saw it being used in RPGXP as well. (More than likely part of ruby scripting)