Public Group

# Beginning C++ issues

This topic is 4892 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

So yeah, Just starting to migrate to C++ from a semester of Java and I am using my school's Visual Studio 2003. I am in Visual C++ and writing a simple program. Very simple. However, the tutorial I am doing this from is using Visual C++ 6.0.
#include <iostream.h>
class CCircle {
public:
CCircle (float x, float y, float r) : m_x(x), m_y(y), m_r(r) {}
~CCircle() {}
float getArea() { (3.14159f * m_r * m_r);}
void setX(float x) { m_x = x; }
void setY(float y) { m_y = y; }
void setR(float r) { m_r = r; }
float getX() { return m_x;}
float getY() { return m_y;}
float getR() { return m_r;}
private:
float m_x;
float m_y;
float m_r;
};

CCircle gblCircle(5.,5.,4.);

int main(int argc, char *argv[]) {
CCircle lclCircle(10.,10.,5.);

cout << "global circle area" << gblCircle.getArea() << end1;
cout << "local circle area" << lclCircle.getArea() << end1;

gblCircle.setR(20.0);
lclCircle.setR(15.0);

cout << "global circle area" << gblCircle.getArea() << end1;
cout << "local circle area" << lclCircle.getArea() << end1;

return 0;
}


I just figured out that .net uses some different standard that says you should instead use the syntax #include <iostream>; so that takes care of one of the errors. But I still get errors when using cout and end1: c:\Documents and Settings\Derek\My Documents\Visual Studio Projects\Circle\Circle.cpp(25) : error C2065: 'cout' : undeclared identifier c:\Documents and Settings\Derek\My Documents\Visual Studio Projects\Circle\Circle.cpp(25) : error C2065: 'end1' : undeclared identifier I would really really appreciate some help. Ever since I started trying to learn C++ I have never gotten comfotable with a compiler and stuff like this would always turn me away from the language. I am at college now and have the opportunity to use a really nice production IDE and don't want it to pass me by! Thanks for any and all assistance! [Edited by - Fruny on July 20, 2005 1:13:57 PM]

##### Share on other sites
Try std::cout and std::endl.

It's endl not a 1, an L in lowercase.

Or you could type using namespace std; right at the top of your code, underneath #include <iostream>

HTH,

ukdeveloper.

##### Share on other sites
Standard library components are placed in the std namespace.
You can add using namespace std; after you #include the headers, selectively import those symbols you want to use by writint using std::cout; ... instead, or fully qualify every reference to the symbol by writing std::cout where you currently have just cout

Additionally, you wrote end1 with the number 1, when the correct symbol is endl with the lowercase letter L.

##### Share on other sites
All parts of the standard library are in the namespace std. This includes cout, endl, string, vector, etc. Also, all old C functions that have the new c prefix are also in namespace std. Put using namespace std; at the top to fix the errors.

##### Share on other sites
Quote:
 Original post by GinkAlso, all old C functions that have the new c prefix are also in namespace std.

Incorrect. What you meant was that every standard C header has a standard C++ counterpart whose name is formed by prefixing with a 'c' and dropping the '.h' extension:

stdlib.h → cstdlibctype.h  → cctypemath.h   → cmath

Symbols in those header files are supposedly placed in the std namespace, but often are not.

##### Share on other sites
oh my gosh guys, you are amazing.I really appreciate your speedy help. I am using a visual tutorial so thats why I wrote the 1. I should probably use O'reillys C++ pocket reference to make sure what I am typing is logical. I feel really silly now. Oh yeah, I also didn't need a semi-colon after including iostream and such, that took care of a few other errors.

So why was there such a change between VC++ 6.0 and the Visual C++ of .NET 2003?

EDIT: Nevermind, there wasn't the same change as I thought. I didn't fully read prior posts...

##### Share on other sites
I say that VC++ 6 is rather useless. Dev-C++ has a more user friendly interface. But, if you want to stick with VC++ 6, then that's fine by me. aybe you could check Dev-C++ out later. Anyways, just curious, are you running your programs from the Run->"Command"?

##### Share on other sites
Quote:
 Original post by killnineSo why was there such a change between VC++ 6.0 and the Visual C++ of .NET 2003?

Because C++ got standardized in 1998, after MSVC++ 6.0 was released.

##### Share on other sites
I wouldn't say Dev-CPP has a better interface. It's fairly buggy and I have wierd issues when I'm trying to debug like it forgetting breakpoints and the stop debugging sometimes doesn't work.

Visual C++ 6.0, even though it has poor template implementation has a fine interface and I wouldn't replace it with Dev-CPP on any windows application programming task.

However, for writing cross-platform application that use and/or abuse templates, I would not use VC++ 6.

##### Share on other sites
Visual C++ 6 wasn't even up to date when it was released in 1998. It's true that the final changes were made in 1998 but the progress of the c++ standardization was over the past years and they could have put a lot of it even in the vc6.
The Visual C++ 2002, 4 years after the standardization, is still very bad when it comes to the standard support.

But Visual C++ 2003 is a very great idea and supports almost the full standard :)

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 9
• 9
• 11
• 11
• 23
• ### Forum Statistics

• Total Topics
633679
• Total Posts
3013294
×