A bit of Success

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • A bit of Success

      Hi all.
      I've sorted my teething problems out. Seems that Visual C++ needs the line:-

      using namespace std;

      at the top of the code or things don't go as planned.
      Problem is, all the code i had looked at didn't include this line so nothing was working for me, even my beginners book dodn't mention it so the code i typed in from that didn't work either!

      Now at least i can really get started! so, i have my beginners book, which book should i now buy to learn about all these STL's and MFC's and API's and how to use them.

      Thanks for your help getting me started.

      eric
    • Things could get hairy if you use namespaces... as it implies that everything is under that namespace, even things that might be under another namespace.

      The most common thing I've seen is this:
      typedef std::list<int> MyIntListType;
      ...
      MyIntListType m_myList;
    • It's generally poor practice to use a blanket statement such as "using namespace std;". As Kain pointed out, it brings in everything under the namespace, whether you use them or not.

      Another thing to keep in mind is that you don't want to put using statements in your header files. Reason being is that when you start including those headers in your own projects, you're bringing in those symbols into the source unit, whether you need them or not. And if you're making a library others will use, users of your library won't know unless they look through your header files. Instead, just use fully qualified names (i.e., std::list rather than saying "using std::list;" at the top of the header then just using list later on).
    • If there's one thing C# has fixed - its the namespace problem, #include madness, and missing libraries in the link.
      Mr.Mike
      Author, Programmer, Brewer, Patriot
    • ok. This is how i now have my little prog' running:-

      #include <iostream>
      using std::cout;
      using std::cin;
      using std::endl;
      int main()
      {
      int a=0;


      cout << "Hello World" <<endl;

      cout << "enter an integer--";
      cin >> a;
      cout << (a)<<endl;
      cout << (a)*(a)<<endl;

      return 0;
      }

      As you can see i'm only up to putting headers at the top of my source code, i haven't yet looked at using the header files VS generates, as far as i know headers go at the top of the code. I'm sure having a seperate file for headers (which i presume it is) is a great idea if you're writing the latest top game but i'm just starting and i like everything where i can see it at the moment. i've no idea what the resource files bit is for, it'd probably scare me back to AmigaBasic if i investigated it's purpose just yet!

      Also won't i end up with loads of these
      using std::xxx;
      things if i need one for each command or have i got it all wrong again?

      Thanks

      eric
    • Originally posted by blastradius
      Also won't i end up with loads of these
      using std::xxx;
      things if i need one for each command or have i got it all wrong again?

      Basically yeah. You need them if you want to use anything in the std namespace without prefixing the std:: part to its name. Although, in my experience with VS.NET 2002, it seemed some things in the C++ standard library aren't placed in the std namespace. I can't remember any off the top of my head (been a while since I've used them), but I was always under the assumption basically anything that's part of the C++ standard library had to be placed under the std namespace.

      The post was edited 1 time, last by MRom ().

    • My copy of VS.NET 2002 will give a compile error if you use cout without either saying using namespace std. or using std::cout. Are you using <iostream> header or <iostream.h> header? The latter is now deprecated, whereas the former declares (or should declare anyways) all the standard input/output objects, such as cout, cin, and cerr, in the std namespace.
    • STL stands for standard template library.

      You may have already learned about some common data structures such as linked list, stack, hash tables, and maps... and strings.

      STL is a standard set of these commonly used structures meant to be widely used so that people will not have to write their own version every time they need to do this. That way, no matter where you work, hopefully, you will be familiar with their basic data structures. The main argument I hear against using STL is that it increases the size of the executable when you may not neccesarily be using all of the features STL is being included into the exe for.

      From sgi.com/tech/stl/stl_introduction.html:
      "The Standard Template Library, or STL, is a C++ library of container classes, algorithms, and iterators; it provides many of the basic algorithms and data structures of computer science. The STL is a generic library, meaning that its components are heavily parameterized: almost every component in the STL is a template. You should make sure that you understand how templates work in C++ before you use the STL."
    • Originally posted by Kain
      sgi.com/tech/stl/stl_introduction.html:

      Damn, I need a new monitor. It took me way too long to find the colon at the end of that url. Hmm... when a site can't be found, IE should suggest possible mistakes like that one.