   Some problems and questions with/about C++ and managed C++ on .NET framework.
  HiI have encountered a few problems and general wonderings in the last few days and would be very greatfull I could receive some help.My first problem is with C++ namesapces and STL library. For some reason when I include an STL component(such as string, vector, map etc.) and include some other libraries in the same *.h file I get hundreds of errors. I have encountered this problem with iostream library and STL in the same *.h file. I did found out that they where under the same namespace -> STD. The problem with iostream and STL was that when I included the libraries like below I had errors. Can anyone explain why? I tried to find an answer in books and stuff like that, but I don''t know I missed it or something.The problem:#include <iostream.h>#include <string>The solution(if I remember correctly):#include <iostream>#include <string>So why this way? I really don''t know and I have failed to find an answer to this problem.Well anyway here''s another similar problem.#ifndef texttext#define texttextnamespace Speeder{#include <string>#include <time.h>#include <sys/types.h>#include <sys/timeb.h>using namespace std;class x {...};}#endifSolution:#ifndef texttext#define texttext#include <string>namespace Speeder{#include <time.h>#include <sys/types.h>#include <sys/timeb.h>using namespace std;class x {...};}#endifI just don''t understand why it''s this way.My second or well third question is releated to managed C++ in .NET framework. Just a day ago I did some exploring on the new VS .NET 2K3 C++ tool and finaly found out the difference between standadized C++ and microsofts managed C++. Well what I found out. Anyway managed C++ looks alot like VB .NET code or C# .NET, the only difference that it''s based on C++. Well thats not important, what is important is the compilers solution between C++ code and managed C++ code in a same project.I''m just wondering how will the compiler compile as an example a windows forms app done offcourse with managed C++ and includingg in this project normal C++ libraries and code of your own.I mean aa..... in managed C++ datatypes are objects like in Java, VB .NET etc... The datatypes object have properties and attributes of their own, which normal C++ datatypes don''t have. I mean it''s a cool idea, but in my opinion is it necesarry?? Anyway I am just wondering how will the compiler compile the normal imported C++ code of my own with the managed C++ code.For a example will a integer datatype variable in my normal C++ code be compiled as a managed C++ object datatype or what... I''d like to know because, managed C++ should clean up itself(memory management the garbage collector), but in normal C or C++ when you allocate memory you must allso see to it that you free it.Well I know it''s a lot of text, but I want to understand. Allso I really have tried to find some sort of answers to my questions, but really I haven''t had much luck. So if anyone can enlight me, I''ll gladly take any help.Knowledge is good. Thanks in advance for any help. 
quote:Original post by Lionheartadi  The problem:#include <iostream.h>#include <string>The solution(if I remember correctly):#include <iostream>#include <string>So why this way? I really don''t know and I have failed to find an answer to this problem.Not really sure what you''re asking here, but I''ll give it a shot.In VC++ 2003, Microsoft removed some of the obsolete header files to make the compiler more ANSI compliant.  So iostream.h no longer exists, you have to use just iostream.  In iostream, everything is in the std namespace so you either need to add a using namespace std; at the top or prefix whatever you are using with std::quote:Well anyway here''s another similar problem.#ifndef texttext#define texttextnamespace Speeder{#include <string>#include <time.h>#include <sys/types.h>#include <sys/timeb.h> using namespace std;class x {...};}#endifSolution:#ifndef texttext#define texttext#include <string>namespace Speeder{#include <time.h>#include <sys/types.h>#include <sys/timeb.h> using namespace std;class x {...};}#endifI just don''t understand why it''s this way.Not a clue about this, probably has something to do with the string header file...quote:My second or well third question is releated to managed C++ in .NET framework. Just a day ago I did some exploring on the new VS .NET 2K3 C++ tool and finaly found out the difference between standadized C++ and microsofts managed C++. Well what I found out. Anyway managed C++ looks alot like VB .NET code or C# .NET, the only difference that it''s based on C++. Well thats not important, what is important is the compilers solution between C++ code and managed C++ code in a same project.I''m just wondering how will the compiler compile as an example a windows forms app done offcourse with managed C++ and includingg in this project normal C++ libraries and code of your own.I mean aa..... in managed C++ datatypes are objects like in Java, VB .NET etc... The datatypes object have properties and attributes of their own, which normal C++ datatypes don''t have. I mean it''s a cool idea, but in my opinion is it necesarry?? Anyway I am just wondering how will the compiler compile the normal imported C++ code of my own with the managed C++ code.For a example will a integer datatype variable in my normal C++ code be compiled as a managed C++ object datatype or what... I''d like to know because, managed C++ should clean up itself(memory management the garbage collector), but in normal C or C++ when you allocate memory you must allso see to it that you free it.The managed C++ compiler allows you to have both native and managed code in the same assembly.  The normal imported code will be compiled into native code, but it will still be accessible from .NET.  This is why MC++ is used for wrappers and such.  For example, if you have a native lib you need to use in C#/J#/VB.NET, you can write a wrapper for it in MC++ and use the wrapper from other code.Not sure how well I explained all that, did it help you? ;  From my experience, you can not use a namespace with in another namespace, as you were trying to use the STD namespace in one of your own. I don’t use namespaces too often so I lack certain knowledge of them. But I think you may have to explicitly use the classes your after, via using std::class_you_want_to_use. All though I may be wrong on that, but at least you have something else to go off of.When you include multiple header files that use the same namespace, you may experience compile time errors if you include them differently. When using #include <iostream> the compiler dose indeed include that code but you may only access the code using via using std::class_you_want_to_use. Or by explicitly using the classes name, such as std::cout << “I love C++” << std::endl. This is because the compiler hasn’t actually defined that class in the namespace unless you tell it explicitly that you are ‘using’ it. The compiler does, however, define the classes with in the namespace if you use the .h in the inclusion directive. This allows you access to the classes with out needing to explicitly asking for them. So when you try to use both at the same time, the compiler chokes and throws error messages about namespaces and inclusion problems. I might be off on this a little bit because I have acquired a concept on how things work over time. So I may not have the words to explain it to you properly.Managed C++ is not that same as Visual Basic.NET. Managed C++ or not, it’s still C++. From what I can remember, using managed applications allow you to interface multiple languages easier. Managed applications provide simple language interoperability with rich type support. An example might be building your own classes in C++ that do various useful tasks, then writing the program that uses them in another language such as Visual Basic.NET with ease. This functionality is known as the .NET Common Language Runtime, or CLR for short. This might be were you’re mixing the C++ with Visual Basic.NET.Programming with WIN32 or any code you may create is still the same in a managed or non-managed application. As said before, managed applications allow you extended interoperability between many different languages. For example, you could program a class, such as you ‘x’ class, and use it in another programming language such as Visual Basic.NET or any other .NET supported languages. While doing this, you can access the class’s interface methods and data members in another choice language.// Example C++ class in a managed applicationclass myClass{public:   int myInt;};‘Example of using the class in another language such as Visual Basicdim myObject as myClassmyObject.myInt = 1Do you see how this works? Try not to think of a managed application any different from a non-managed one. But try to think of a managed application adding the possibility for you to incorporate what you programmed in one language, into different one. Besides the language interoperability, there is no real difference between a managed and non-managed application.I hope I have helped you with my reply. If you are ever wanted to know any information about Microsoft’s APIs, try searching on Google or MSDN. These two places will most likely have your answer. Good luck on you programming and I hope you success in what ever you are trying to accomplish.;  Thanks for all of your replies. They did clarify some things to me thanks. Well what comes to the managed C++ question, there where allso new and enlighting replies. Thx, but I still fear to use them. After hearing or to be more specific after reading on a forum, that the C++ language was modified by Microsoft so thath it could become this managed version, type, thing... One of such modification I think, was the memory management stuff. This scares me a bit, because just a few weeks ago I started reading from these two(in my opinion) good books. They are writen by Scot Meyers. The books where Effective C++ and More effective C++. Those books really did clarify for me the C++ language more deaply than I ever knew. Well what I''m trying to say changes like this by Microsoft are scary, because "are these changes approved as a standard to c++"... Uh... Well I don''t know I look into it and will have to see what happens in the future, but I will say this when I make a project with one language I really 90 % of the time don''t care if I can port it to another language. Thanks for the responses they did help. I''ll have to study more.  thx. 