Help learning C++

L

Lee

Ok, just starting out teaching myself C++. I purchased Sams Teach
Yourself C++. Years ago, I purchased a similar book for C. So with
that having been said. I am running Ubuntu Linux, Anjuta IDE, which
uses G++ compiler. (Just giving you my system to help you help me.)
I've typed in the following example:

#include <iostream>
int main()
{
int x = 5;
int y = 7;
std::cout << endl;
std::cout << x + y << " " x * y;
std::cout << end;
return 0;
}

And get the following errors when it compiles it.
error: endl was not declared in this scope
error: expected `;' before 'x'
error: end was not declared in this scope

So... Seeing as this is the second piece of code they have me type in,
and already I am getting errors. I was hoping for a little help. When
Anjuta compiles the file it does so as such:

g++ -c "example.cc" -o "example.o"

Thank you folks in advance for your help. No this is not a college or
high school class. I am 42 and looking to learn C++ for the heck of
it. Thanks again.
 
R

red floyd

Lee said:
Ok, just starting out teaching myself C++. I purchased Sams Teach
Yourself C++. Years ago, I purchased a similar book for C. So with
that having been said. I am running Ubuntu Linux, Anjuta IDE, which
uses G++ compiler. (Just giving you my system to help you help me.)
I've typed in the following example:

#include <iostream>
int main()
{
int x = 5;
int y = 7;
std::cout << endl;
std::cout << std::endl;
std::cout << x + y << " " x * y;
std:: << x + y << " " << x * y;
std::cout << end;
std::cout << std::endl;
return 0;
}

And get the following errors when it compiles it.
error: endl was not declared in this scope
error: expected `;' before 'x'
error: end was not declared in this scope
Your compiler told you exactly what was wrong.

1. std::endl, not endl;
2. you missed a <<
3. you made a typo, there's no end declared, and endl is in std:: anyways.
 
I

Ian Collins

Lee said:
Ok, just starting out teaching myself C++. I purchased Sams Teach
Yourself C++. Years ago, I purchased a similar book for C. So with
that having been said. I am running Ubuntu Linux, Anjuta IDE, which
uses G++ compiler. (Just giving you my system to help you help me.)
I've typed in the following example:

#include <iostream>
int main()
{
int x = 5;
int y = 7;
std::cout << endl;

std::cout << std::endl;
^^^^^
std::cout << x + y << " " x * y;

std::cout << x + y << " " << x * y;
^^
 
L

Lee

Your compiler told you exactly what was wrong.

1. std::endl, not endl;
2. you missed a <<
3. you made a typo, there's no end declared, and endl is in std:: anyways.

Thanks. I looked at the code in the book, and they had part of it
wrong then. The "std::cout << endl;" is straight from the book. I
did forget to put in the << in the next line, and they had the
"std::cout << end;". <sigh> So, the code in the examples are wrong.
Thanks! I appreciate your help.

Lee
 
R

red floyd

Lee said:
Thanks. I looked at the code in the book, and they had part of it
wrong then. The "std::cout << endl;" is straight from the book. I
did forget to put in the << in the next line, and they had the
"std::cout << end;". <sigh> So, the code in the examples are wrong.
Thanks! I appreciate your help.

A better book, that teaches "C++ style" thinking instead of C thinking,
right from the start is "Accelerated C++" by Koenig and Moo. Highly
recommended.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top