locked
using std namespace

    Question

  • Gad, I'm so embarrassed to ask this.

    I'm transitioning from c#/xna to c++/directX, vs11 (metro). I am playing with the direct2dApplication1 sample. I can't figure out how to get set up to utilize a std::vector.

    If I look in the sample game, "metro style 3d shooting game sample", I can see where it utilizes std::vector to declare a collection. But I am unable to see exactly what "includes" or "using" statements it has hidden away somewhere to be able to use it. In this sample, if I start to  type 'std'... it comes right up on intelisense and leads me to vector.

    Typing this in my direct2dApplication1 sample does not lead me on. I'm smart enough to know it is somehow not included in the references but can you tell me how, specifically, to get it there?

    Sorry for a bonehead question. I learned c# first.

    Thanks

    Wednesday, March 21, 2012 11:59 PM

Answers

  • "#include <vector>" to include the correct header and then std::vector<T> should work for you.

    "using namespace std;" if you want to avoid std:: everywhere

    -Steve

    Thursday, March 22, 2012 12:14 AM
    Moderator

All replies

  • "#include <vector>" to include the correct header and then std::vector<T> should work for you.

    "using namespace std;" if you want to avoid std:: everywhere

    -Steve

    Thursday, March 22, 2012 12:14 AM
    Moderator
  • Its likley in a precompiled header.

    #include <vector>

    For C++ development, it is generally recommended to avoid 'global' usage of things like "using std;". You can do that in a specific module, but it's not a good idea in headers. In many cases, it's best to avoid using statements and try to do explicit resolution (or create a typedef as an alias).

    I presonally recommend anyone new to C++ or who hasn't used C++ in many years to pick up all three Scott Meyers books and read them. They are a little out of date compared to C++11, but they cover a lot of stuff that is now 'assumed' like namespaces, exception handling, STL, etc.

    Effective C++

    More Effective C++

    Effective STL

    Thursday, March 22, 2012 12:15 AM
  • Thank you Steve, That did seem to work but for some reason I wasn't able to declare a vector<string>.  Intelisense didn't offer 'string'.

    Going off to amazon now to purchase books recommended by Chuck.

    Thank you.


    • Edited by Shazen Thursday, March 22, 2012 12:26 AM
    Thursday, March 22, 2012 12:25 AM
  • I get it now: std::vector<std::string> myItems;
    Thursday, March 22, 2012 12:46 AM