If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Compiler error with cout object

Hello, I am asp.net C# developer. I decided to tackle C++, so I started today. This is probably something simple I am sure but I cannot figure out what the problem is. I would appreciate if someone could show me what is wrong and why.

Re: Compiler error with cout object

Originally Posted by remojr76

Hello, I am asp.net C# developer. I decided to tackle C++, so I started today. This is probably something simple I am sure but I cannot figure out what the problem is. I would appreciate if someone could show me what is wrong and why.

Recognize the correct header files to include for each class that you use in your program.

The std::string class requires <string>, but you did not include it.

Second, when you post code that doesn't compile, it is always best to post the smallest complete code, without breaks, as to what doesn't compile. In other words, one edit window, where it just requires a copy and paste of the entire code in the compiler to see the error. To duplicate your error, I would have to rearrange the code, introduce #define constants, add ending curly braces, etc (and I still may not be able to duplicate your error after all of that work).

Last, C++ is much different than C# in many ways. Try to access an array out-of-bounds in C++, and do the same thing in C#. Run the program and tell us what happens with each. Don't be surprised if the C++ program just goes on its merry way as if nothing is wrong. That is the major difference between the two languages at runtime -- C++ allows wrong programs to run hapharzardly, while C# will automatically tell you that you've done something wrong.

Excluding the precompiled header "stdafx.h" (which is not required if all you're doing is learning C++), the code above compiles correctly. The code is an example of a complete program. Whether it runs correctly or not isn't important if the goal is to show what compiles and what doesn't compile correctly.

Re: Compiler error with cout object

Quit a difference with the array, instead of an out of bounds exception, I got an error saying I was trying to use a variable that had not been initialized.

In reality, there is no guarantee if you receive any message whatsoever. Compile a release version and you will see that message doesn't show up.

Again, C++ is not C#. C++ has something called undefined behaviour, where if you make a mistake, there is no guarantee how your program will run -- it may even "work" on your machine and fail on another machine.

I am assuming that when I use a using statement I am making a reference to a dll. correct?

No. The using clause introduces a namespace to the current source file.

I am also assuming that when I use an #include its a reference to a class in that dll.?

No.

There is no "dll" in C++. C++ is a general purpose language that knows nothing about DLL's. What you have is a text file that contains C++ source code, and the compile checks the syntax, and if it's OK, produces an intermediate object file. It is then the linker that links these object files into a final executable.

if my assumptions are correct why do you need to use an #include when you are using the namespace that the class is in?

Your assumptions are so far off, I highly suggest you get a book on C++ programming instead of guessing and equating parts of C++ to C#. The biggest mistake you would make is to assume that C++ and C# are the same, but with only different syntax. C++ is a language you cannot learn on assumptions or learn based on another language you may have used.

You must start with the basics, otherwise you'll just produce applications that are either so buggy and/or coded so poorly that it is obvious to a seasoned C++ programmer that the code was produced by someone who doesn't know the language.